changeset 10:370a1eeb8812

merge and stuff
author William Morgan <bill@mrgn.org>
date Sat, 14 Jul 2012 01:58:43 -0700
parents 66ea6fdd3fcb
children f28e465e9ee6
files src/sim.tp
diffstat 1 files changed, 45 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sat Jul 14 01:46:25 2012 -0700
+++ b/src/sim.tp	Sat Jul 14 01:58:43 2012 -0700
@@ -1,4 +1,6 @@
 #{
+
+	// utilities 
 	true <- #{
 	  if:else <- :self trueblock :elseblock {
 		trueblock:
@@ -11,12 +13,25 @@
 	  }
 	}
 
+	foreach <- :string action {
+		strLen <- string byte_length:
+		index <- 0
+		while: {index < strLen} do {
+			element <- (string byte: index)
+			action: index element
+			index <- index + 1
+		}
+	}
+	// end utilities
+
+
 	cellTypes <- #{
 		allstr <- #[]
 		allobj <- #[]
-		make <- :idstr {
+		new <- :idstr {
 			ret <- #{
 				id <- (idstr byte: 0)
+				isrobot <- { false }
 			}
 			allobj append: ret
 			allstr append: idstr
@@ -39,35 +54,37 @@
 				}
 			}
 		}
-		wall        <- make: "#"
-		empty       <- make: " "
-		earth       <- make: "."
-		rock        <- make: "*"
-		lambda      <- make: "\\"
-		closedlift  <- make: "L"
-		openlift    <- make: "O"
-		newline     <- make: "\n"
+		wall        <- new: "#"
+		empty       <- new: " "
+		earth       <- new: "."
+		rock        <- new: "*"
+		lambda      <- new: "\\"
+		closedlift  <- new: "L"
+		openlift    <- new: "O"
+		newline     <- new: "\n"
 		robot       <- {
 		#{
 			id <- ("R"  byte: 0) 
+			isrobot <- { true }
 			heldBreath <- 0
 		}
     }
 
 	state <- #{
 		new <- :in_grid in_width in_height { 
-			next_grid <- #[]
+			nextGrid <- #[]
+			robot <- false
 			foreach: in_grid :index el{
-				next_grid append: el
+				nextGrid append: el
+				if: (el isrobot) { robot <- el } else: { true }
 			}
 			#{
 				grid <- in_grid
 				width <- in_width
 				height <- in_height
-				robot <- cellTypes robot
 				address <- :x y { x + y * width }
-				setCell <- :x y cell {
-					grid set: (address: x y) cell
+				setCell <- :x y val {
+					grid set: (address: x y) val
 				}
 				getCell <- :x y {
 					grid get: (address: x y)
@@ -99,14 +116,23 @@
 			}
 		}
 		fromStr <- :str {
+
 			strLen <- str byte_length:
-			index <- 0
 			maxRow <- 0
 			curRow <- 0
-			while: {index < strLen} do: {
-				curByte <- str byte: index
-				if: curByte = (cellType newline id) {
-					maxRow <- if: curRow > maxRow {curRow} else: {maxRow}
+			foreach: str :index element {
+				if: element = ((cellTypes newline) id) {
+					maxRow <- if: curRow > maxRow {curRow} else: {maxRow}					
+					curRow <- 0
+				} else: {
+					curRow <- curRow + 1
+				}
+			}
+			
+			foreach: str :index element {
+				if: element = ((cellTypes newline) id) {
+					// add spaces
+					curRow <- 0
 				} else: {
 					curRow = curRow + 1
 				}