42 lines
1.1 KiB
Haskell
42 lines
1.1 KiB
Haskell
|
module Navigation where
|
||
|
|
||
|
import Affection as A
|
||
|
|
||
|
import Data.Matrix as M
|
||
|
import qualified Data.HashSet as HS
|
||
|
import Data.Graph.AStar
|
||
|
import Data.Maybe (isJust)
|
||
|
|
||
|
import Linear
|
||
|
|
||
|
-- internal imports
|
||
|
|
||
|
import Types.Map
|
||
|
import Types.UserData
|
||
|
import Types.Interior
|
||
|
|
||
|
isReachable :: Matrix (Maybe ImgId) -> [V2 Int] -> [ReachPoint] -> Bool
|
||
|
isReachable imgmat reaches exits =
|
||
|
let astarAppl ex rc = aStar
|
||
|
(naviGraph imgmat)
|
||
|
(\a b -> distance (fmap fromIntegral a) (fmap fromIntegral b))
|
||
|
(\a -> distance (fmap fromIntegral ex) (fmap fromIntegral a))
|
||
|
(== ex)
|
||
|
rc
|
||
|
result =
|
||
|
(concatMap
|
||
|
(\exit -> map (astarAppl exit) reaches)
|
||
|
(map pointCoord exits))
|
||
|
in all isJust result
|
||
|
|
||
|
naviGraph :: Matrix (Maybe ImgId) -> V2 Int -> HS.HashSet (V2 Int)
|
||
|
naviGraph imgmat (V2 r c) =
|
||
|
let list = foldl
|
||
|
(\acc (or, oc) -> if null (imgObstacle $ imgmat M.! (r + or, c + oc))
|
||
|
then if or == 0 && oc == 0 then acc else V2 (r + or) (c + oc): acc
|
||
|
else acc
|
||
|
)
|
||
|
[]
|
||
|
[(0, 1), (0, -1), (1, 0), (-1, 0)]
|
||
|
in HS.fromList list
|