changeset 5:be946b2a2cbc

initial barf into simulator file
author William Morgan <bill@mrgn.org>
date Fri, 13 Jul 2012 21:10:10 -0700
parents d4ba6138c99e
children 86cdb799f950
files src/sim.tp
diffstat 1 files changed, 109 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Fri Jul 13 18:25:35 2012 -0700
+++ b/src/sim.tp	Fri Jul 13 21:10:10 2012 -0700
@@ -1,5 +1,113 @@
 #{
+	true <- #{
+	  if:else <- :self trueblock :elseblock {
+		trueblock:
+	  }
+	}
+
+	false <- #{
+	  if:else <- :self trueblock :elseblock {
+		elseblock:
+	  }
+	}
+
+	cellType <- # {
+		robot       <- "R" byte 0
+		wall        <- "#" byte 0
+		rock        <- "*" byte 0
+		lambda      <- "\" byte 0
+		closedlift  <- "L" byte 0
+		openlift    <- "O" byte 0
+		earth       <- "." byte 0
+		empty       <- " " byte 0
+		newline     <- "\n" byte 0
+    }
+
+	state <- #{
+		new <- : in_grid in_width in_height { 
+			dst_grid <- #[]
+			foreach: in_grid :index el{
+				dst_grid append: el
+			}
+			#{
+				grid <- []
+				width <- in_width
+				height <- in_height
+				address <- :x y { x + y * width }
+				setCell <- :x y cell {
+					grid set: (address: x y) cell
+				}
+				getCell <- :x y {
+					grid get: (address: x y)
+				}
+				collected <- 0
+				moves <- 0
+				ended <- false
+				advance <- :roboMove {
+					nextState <- deepCopy: self
+					nextState <- doMove:
+					nextState ended <- ended:
+					nextState moves <- moves + 1
+				}
+				
+			}
+		}
+		fromStr <- :str {
+			strLen <- str byte_length:
+			index <- 0
+			maxRow <- 0
+			curRow <- 0
+			while: {index < strLen} do {
+				curByte <- str byte: index
+				if: curByte = (cellType newline) {
+					
+				} else: {
+					curRow = curRow + 1
+				}
+			}
+			grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0)  (			                 "#" byte: 0) (" " byte: 0) ("#" byte: 0)  (			                 "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] 
+			fresh <- new: grid 3 3
+		}
+		deepCopy <- :oldState {
+			newState <- new: 
+			#{
+				// grid <- (use array copy thing)
+				width <- oldState width
+				height <- oldState height
+				address <- oldState address
+				// ... better way?
+			}
+		}
+	}
+
+	testMoves <- {
+		myStep <- 0
+		{
+			print: (string: myStep)
+			myStep <- myStep + 1
+			if: myStep > 5 {"A"} else: {"W"}
+		}
+	}
+	
+	ended <- :simState roboMove {
+		if: roboMove = "A" {}
+	}
+
 	main <- {
-		0
+		
 	}
+
+/*
+	main <- {
+		testInput <- "derp" 
+		simState <- state fromStr: testInput
+		roboMove <- "W"
+		getMove <- testMoves:
+		while: {playing: simState roboMove} do: {
+			print: "step..."
+			roboMove <- getMove:
+			simState advance:
+		}
+	}
+*/
 }