type PointOfInterest = M.Map Position Char
-class (Eq e, Ord e) => ExplorerC e where
+class (Eq e, Ord e, Show e) => ExplorerC e where
successors :: e -> CaveContext (Q.Seq e)
estimateCost :: e -> CaveContext Int
-- positionE :: e -> Position
main :: IO ()
main = do
- text <- readFile "data/advent18.txt"
+ text <- readFile "data/advent18x.txt"
let (cc, explorer) = buildCaveComplex text
-- print cc
-- print explorer
let reached = _current currentAgendum
nexts <- candidates currentAgendum closed
let newAgenda = foldl' (\q a -> P.insert (_cost a) a q) (P.deleteMin agenda) nexts
+ -- let newAgenda = trace ("nexts " ++ ( show nexts)) newAgenda0
reachedGoal <- isGoal reached
if reachedGoal
then return (Just currentAgendum)
candidates :: ExplorerC e => Agendum e -> ExploredStates e -> CaveContext (Q.Seq (Agendum e))
+-- candidates a _ | trace ("Cand " ++ show (a)) False = undefined
candidates agendum closed =
do let candidate = _current agendum
let previous = _trail agendum
mapM (makeAgendum candidate previous) nonloops
makeAgendum :: ExplorerC e => e -> (Q.Seq e) -> e -> CaveContext (Agendum e)
+-- makeAgendum c _p n | trace ("Agendum " ++ (show c) ++ " " ++ (show n) ) False = undefined
makeAgendum candidate previous new =
do cost <- estimateCost new
return Agendum { _current = new
allSplits xs = S.map (\x -> (x, S.delete x xs)) xs
setToSeq :: Ord a => S.Set a -> Q.Seq a
-setToSeq = S.foldl (|>) Q.empty
+setToSeq xs = foldl' (|>) Q.empty $ S.toAscList xs