~vonfry/maze-escape

23d1102864f4085df084e25f8fcf2c6e7420c785 — Vonfry 2 years ago f50fed8
maze: fix
1 files changed, 9 insertions(+), 1 deletions(-)

M lib/Game/Maze.hs
M lib/Game/Maze.hs => lib/Game/Maze.hs +9 -1
@@ 1,5 1,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

module Game.Maze (MovableCell(..), Maze2D(..)) where



@@ 35,7 36,14 @@ type RMapEscapeState pos = State (Map pos (MapEscapeMark pos))
type RMapEscape map pos = ReaderT map (RMapEscapeState pos) [pos]

filterMinLength :: [[pos]] -> [pos]
filterMinLength = minimumBy $ comparing length
filterMinLength poss =
  case filterOutNull poss of [] -> []
                             poss -> filterByMin poss
    where
      filterByMin = minimumBy $ comparing length

filterOutNull = filter $ not . null


dfs :: Maze2D map pos cell => [pos] -> RMapEscape (map pos cell) pos
dfs = fmap filterMinLength . traverse dfs'