X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=code%2FSokoban.icl;h=804a7cd86d37ac243c8f99dc8edd020dd31a14e6;hb=528cda8a5116dbed02a1e603d7fca2033dd0c100;hp=2788930f4060e48306e4b85bf9bc06430ea0baa1;hpb=d16ccad512857e1469e3b3cb7ff28abc6ca8a46a;p=mc1516pa.git diff --git a/code/Sokoban.icl b/code/Sokoban.icl index 2788930..804a7cd 100644 --- a/code/Sokoban.icl +++ b/code/Sokoban.icl @@ -25,15 +25,24 @@ instance toString SokobanTile where toString TargetBox = "*" toString TargetAgent = "+" +parseFromFile :: *File -> (SokobanPuzzle, *File) +parseFromFile f +# (contents, f) = readEntireFile f +| isEmpty contents = abort "File is empty or unreadable" += (Sokoban (parseRows contents), f) + parse :: String *World -> (SokobanPuzzle, *World) parse fp w # (ok, f, w) = fopen fp FReadText w | not ok = abort ("Couldn't open file: '" +++ fp +++ "'") -# (contents, f) = readEntireFile f -| isEmpty contents = abort "File is empty or unreadable" +# (puzzle, f) = parseFromFile f # (ok, w) = fclose f w | not ok = abort "Couldn't close file" -= (Sokoban (parseRows contents), w) += (puzzle, w) + +numberOfBlocks :: SokobanPuzzle -> Int +numberOfBlocks (Sokoban bs) = let fbs = flatten bs in + length ([1\\(Box)<-fbs] ++ [1\\(TargetBox)<-fbs]) parseRows :: [Char] -> [[SokobanTile]] parseRows cs = case parseRow cs of