X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=code%2FSokobanObjectwise.icl;h=558cc4f2c83430b78602fb9239f5969ed109038a;hb=528cda8a5116dbed02a1e603d7fca2033dd0c100;hp=f234ae1ed96fffc984a8fd89ee74b8ebbfe5806d;hpb=81190f3341c4f7f12529ffa32f5f6a3ca984da77;p=mc1516pa.git diff --git a/code/SokobanObjectwise.icl b/code/SokobanObjectwise.icl index f234ae1..558cc4f 100644 --- a/code/SokobanObjectwise.icl +++ b/code/SokobanObjectwise.icl @@ -1,5 +1,51 @@ module SokobanObjectwise +import StdString +import StdFile +import StdTuple +import StdFunc +import StdOrdList +import StdList import Sokoban -Start = "hi" +Start :: *World -> *World +Start w +# (io, w) = stdio w +# (puzzle, io) = parseFromFile io +# io = io <<< encode puzzle <<< "\n" += snd (fclose io w) + +encode :: SokobanPuzzle -> String +encode p = foldr ((+++) o (+++) "\n") "" ([ + "MODULE", + "main", + "VAR":encodeBoxes p maxX maxY]) + where + annot = annotate p + (maxX, maxY) = getMetrics annot + +:: AnnotatedSokoban :== [(Int, Int, SokobanTile)] + +annotate :: SokobanPuzzle -> AnnotatedSokoban +annotate (Sokoban p) = flatten [[(x, y, t)\\t<-r & x<-[0..]]\\r<-p & y<-[0..]] + +getMetrics :: AnnotatedSokoban -> (Int, Int) +getMetrics p = (maxList (map fst3 p),maxList (map snd3 p)) + +getBoxes :: AnnotatedSokoban -> [(Int, Int)] +getBoxes p = [t\\t=:(_, _, Box)<-p] ++ + + where + getBox` _ [] = [] + getBox` x [b:bs] = let r = getBox` (x+1) bs in case b of + Box = [x:r] + TargetBox = [x:r] + _ = r + +(<+) infixr 5 :: a b -> String | toString a & toString b +(<+) a b = toString a +++ toString b + +encodeBoxes :: SokobanPuzzle Int Int -> [String] +encodeBoxes p mx my = [ + "\tbox" <+ i <+ "x: " <+ "0 .. " <+ mx <+ ";\n\tbox" <+ + i <+ "y: " <+ "0 .. " <+ my <+ ";"\\(bx, by)<-getBoxes p & i<-[0..]]