-encodeObPosition b p = join " | " [
- "(" <+ b <+ "x=" <+ x <+ " & " <+
- b <+ "y=" <+ y <+ ")"\\ (x, y)<-p]
-
-encodeAgentInit :: (Int, Int) -> String
-encodeAgentInit (x, y) = "\tagentx=" <+ x <+ " & " <+ "agenty=" <+ y
-
-encodeAgentVars :: Int Int -> String
-encodeAgentVars mx my =
- "\tagentx: 0.." <+ mx <+ ";\n\tagenty: 0.." <+ my <+ ";\n"
-
-encodeAgentPositions :: [(Int, Int)] -> String
-encodeAgentPositions p = encodeObPosition "agent" p
-
-encodeAgentMovement :: String
-encodeAgentMovement = "TRANS next(agentx) = agentx + dx;\n" <+
- "TRANS next(agenty) = agenty + dy;"
-
-encodeBoxInit :: [(Int,Int)] -> String
-encodeBoxInit bs = join " &\n" [
- "\tb" <+ i <+ "x=" <+ x <+ " & " <+
- "b" <+ i <+ "y=" <+ y
- \\(x, y)<-bs & i<-[0..]]
-
-encodeBoxVars :: [Int] Int Int -> String
-encodeBoxVars p mx my = join "\n"
- ["\tb" <+ i <+ "x: 0.." <+ mx <+ ";\n" <+
- "\tb" <+ i <+ "y: 0.." <+ my <+ ";" \\ i<-p]
-
-encodeBoxPositions :: [Int] [(Int, Int)] -> String
-encodeBoxPositions bs ps = join "\n" [
- "INVAR " <+ encodeObPosition ("b" <+ b) ps <+ ";"\\b<-bs]
+encodeObPosition b p = join " |\n\t" [forThisX b x p\\x<-removeDup $ map fst p]
+ where
+ forThisX :: String Int [(Int, Int)] -> String
+ forThisX s cx p = "(" <+ s <+ "x=" <+ cx <+ " & (" <+
+ join " | " [s <+ "y=" <+ y \\(x, y)<-p | x == cx] <+ "))"
+
+encodeObInit :: String (Int, Int) -> String
+encodeObInit s (x, y) = "\t" <+ s <+ "x=" <+ x <+ " & " <+ s <+ "y=" <+ y
+
+encodeObVar :: String Int Int -> String
+encodeObVar s mx my = "\t" <+ s <+ "x: 0.." <+ mx <+ ";\n" <+
+ "\t" <+ s <+ "y: 0.." <+ my <+ ";\n"