type CaveContext = Reader Cave
-
data Agendum s =
Agendum { _current :: s
, _trail :: Q.Seq s
class (Eq s, Ord s, Show s) => SearchState s where
unwrapPos :: s -> BasePosition
+ emptySearchState :: s
successors :: s -> CaveContext (Q.Seq s)
estimateCost :: s -> CaveContext Int
- emptySearchState :: s
isGoal :: s -> CaveContext Bool
entryCost :: s -> CaveContext Int
emptySearchState = Position (V2 0 0)
-- successors :: Position -> CaveContext (Q.Seq Position)
- successors here =
+ successors (Position here) =
do grid <- asks _grid
let neighbours =
filter (inRange (bounds grid))
- [ (unwrapPos here) ^+^ delta
+ [ here ^+^ delta
| delta <- [V2 -1 0, V2 1 0, V2 0 -1, V2 0 1]
]
let succs = Q.fromList $ map Position neighbours
return succs
-- estimateCost :: Position -> CaveContext Int
- estimateCost here =
+ estimateCost (Position here) =
do goal <- asks _goal
- let (V2 dr dc) = (unwrapPos here) ^-^ goal
+ let (V2 dr dc) = here ^-^ goal
return $ (abs dr) + (abs dc)
-- isGoal :: here -> CaveContext Bool
- isGoal here =
+ isGoal (Position here) =
do goal <- asks _goal
- return $ (unwrapPos here) == goal
+ return $ here == goal
- entryCost here =
+ entryCost (Position here) =
do grid <- asks _grid
- return $ grid ! (unwrapPos here)
+ return $ grid ! here
instance SearchState TiledPosition where
- emptySearchState = TiledPosition (V2 0 0)
-
unwrapPos (TiledPosition p) = p
+ emptySearchState = TiledPosition (V2 0 0)
+
-- successors :: Position -> CaveContext (Q.Seq Position)
successors (TiledPosition here) =
do grid <- asks _grid