generation with model stub (still prototyping)
[mc1516pa.git] / code / SokobanCoord.icl
index 0cce0c4..a2379b7 100644 (file)
@@ -1,4 +1,4 @@
-module SokobanCoord
+module SocobanCoord
 
 import StdList, StdInt, StdChar, StdMisc, StdClass, StdString, StdFile, StdArray, StdTuple, Data.Maybe, Data.Map, Control.Monad, Data.Tuple, Data.Void
 
@@ -15,8 +15,6 @@ puzzle = [[Wall, Wall, Wall, Wall, Wall,   Wall],
           [Wall, Free, Free, Free, Target, Wall],
           [Wall, Wall, Wall, Wall, Wall,   Wall]]
 
-size :: (Int, Int)
-size = (4,5)
 
 checkX :: Int -> Int
 checkX x = if (x > length (hd puzzle)) (-1) x
@@ -24,54 +22,14 @@ checkX x = if (x > length (hd puzzle)) (-1) x
 checkY :: Int -> Int
 checkY y = if (y > length puzzle) (-1) y
 
-/*
-  next(x2_2) := case
-    x2_2 = Wall: Wall;
-
-    x2_2 = Free & x2_3 = Agent & move = Left: Agent;
-    x2_2 = Free & x3_2 = Agent & move = Up: Agent;
-    x2_2 = Free & x2_1 = Agent & move = Right : Agent;
-    x2_2 = Free & x1_2 = Agent & move = Down : Agent;
-
-    x2_2 = Free & x2_3 = Box & x2_4 = Agent & move = Left: Box;
-    x2_2 = Free & x3_2 = Box & x4_2 = Agent & move = Up: Box;
-    x2_2 = Free & x2_1 = Box & x2_0 = Agent & move = Right : Box;
-    x2_2 = Free & x1_2 = Box & x0_2 = Agent & move = Down : Box;
-
-    x2_2 = Agent & (x2_3 = Free | x2_3 = Target) & move = Right: Free;
-    x2_2 = Agent & (x3_2 = Free | x3_2 = Target) & move = Down: Free;
-    x2_2 = Agent & (x2_1 = Free | x2_1 = Target) & move = Left : Free;
-    x2_2 = Agent & (x1_2 = Free | x1_2 = Target) & move = Up : Free;
-
-    x2_2 = Box & x2_3 = Agent & (x2_1 = Free | x2_1 = Target) & move = Left: Agent;
-    x2_2 = Box & x3_2 = Agent & (x1_2 = Free | x1_2 = Target) & move = Up: Agent;
-    x2_2 = Box & x2_1 = Agent & (x2_3 = Free | x2_3 = Target) & move = Right : Agent;
-    x2_2 = Box & x1_2 = Agent & (x3_2 = Free | x3_2 = Target) & move = Down : Agent;
-
-    x2_2 = Target & x2_3 = Agent & move = Left: AgentOnTarget;
-    x2_2 = Target & x3_2 = Agent & move = Up: AgentOnTarget;
-    x2_2 = Target & x2_1 = Agent & move = Right : AgentOnTarget;
-    x2_2 = Target & x1_2 = Agent & move = Down : AgentOnTarget;
-
-    x2_2 = Target & x2_3 = Box & x2_4 = Agent & move = Left: BoxOnTarget;
-    x2_2 = Target & x3_2 = Box & x4_2 = Agent & move = Up: BoxOnTarget;
-    x2_2 = Target & x2_1 = Box & x2_0 = Agent & move = Right : BoxOnTarget;
-    x2_2 = Target & x1_2 = Box & x0_2 = Agent & move = Down : BoxOnTarget;
-
-    x2_2 = AgentOnTarget & (x2_3 = Free | x2_3 = Target) & move = Right: Target;
-    x2_2 = AgentOnTarget & (x3_2 = Free | x3_2 = Target) & move = Down: Target;
-    x2_2 = AgentOnTarget & (x2_1 = Free | x2_1 = Target) & move = Left : Target;
-    x2_2 = AgentOnTarget & (x1_2 = Free | x1_2 = Target) & move = Up : Target;
-
-    x2_2 = BoxOnTarget & x2_3 = Agent & (x2_1 = Free | x2_1 = Target) & move = Left: AgentOnTarget;
-    x2_2 = BoxOnTarget & x3_2 = Agent & (x1_2 = Free | x1_2 = Target) & move = Up: AgentOnTarget;
-    x2_2 = BoxOnTarget & x2_1 = Agent & (x2_3 = Free | x2_3 = Target) & move = Right : AgentOnTarget;
-    x2_2 = BoxOnTarget & x1_2 = Agent & (x3_2 = Free | x3_2 = Target) & move = Down : AgentOnTarget;
-
-    TRUE : x2_2;
-  esac;
-
-*/
+genVars :: Int Int -> [String]
+genVars x y = genVars` x y 0 0 []
+where
+  genVars` :: Int Int Int Int [String] -> [String]
+  genVars` a b x y res
+    | (a+1) == x = res
+    | b == y = genVars` a b (x+1) 0 ["    x" +++ toString x +++ "_" +++ toString y +++ " : {Wall, Free, Box, BoxOnTarget, Target, Agent, AgentOnTarget};\n":res]
+    | otherwise = genVars` a b x (y+1) ["    x" +++ toString x +++ "_" +++ toString y +++ " : {Wall, Free, Box, BoxOnTarget, Target, Agent, AgentOnTarget};\n":res]
 
 genCoord :: Int Int -> [String]
 genCoord x y = ["  next(x" +++ toString x +++ "_" +++ toString y +++ ") := case\n",
@@ -112,11 +70,47 @@ genCoord x y = ["  next(x" +++ toString x +++ "_" +++ toString y +++ ") := case\
                 "  esac;\n"
                 ]
 
-/*
-genAll :: SokobanPuzzle -> [[String]]
-genAll p = [\\]
-genAll [x:xs] = []
-*/
+genAll :: [String]
+genAll = [
+          "MODULE main\n",
+          "VAR\n"
+          ]
+      ++ genVars ((length puzzle) - 1) ((length (hd puzzle)) - 1)
+      ++ [
+          "ASSIGN",
+          "init(x0_0) := Wall;", //currently just a stub
+          "init(x0_1) := Wall;",
+          "init(x0_2) := Wall;",
+          "init(x0_3) := Wall;",
+          "init(x0_4) := Wall;",
+          "init(x0_5) := Wall;",
+          "init(x1_0) := Wall;",
+          "init(x1_1) := Free;",
+          "init(x1_2) := Free;",
+          "init(x1_3) := Free;",
+          "init(x1_4) := Free;",
+          "init(x1_5) := Wall;",
+          "init(x2_0) := Wall;",
+          "init(x2_1) := Agent;",
+          "init(x2_2) := Free;",
+          "init(x2_3) := Box;",
+          "init(x2_4) := Free;",
+          "init(x2_5) := Wall;",
+          "init(x3_0) := Wall;",
+          "init(x3_1) := Free;",
+          "init(x3_2) := Free;",
+          "init(x3_3) := Free;",
+          "init(x3_4) := Target;",
+          "init(x3_5) := Wall;",
+          "init(x4_0) := Wall;",
+          "init(x4_1) := Wall;",
+          "init(x4_2) := Wall;",
+          "init(x4_3) := Wall;",
+          "init(x4_4) := Wall;",
+          "init(x4_5) := Wall;",
+          "init(move) := {Up, Down, Left, Right};"
+         ]
+      ++ flatten [filter (\x -> not (contains '-' x)) (genCoord x y) \\ x <- [0..4], y <- [0..5]]
 
 contains :: Char String -> Bool
 contains char str = not (isEmpty [c\\c<-:str | char == c])
@@ -148,6 +142,4 @@ closeFile world file
   # world = fclose file world
   = world
 
-
-
-Start = flatten [filter (\x -> not (contains '-' x)) (genCoord x y) \\ x <- [0..4], y <- [0..5]]
+Start = genAll