changeset 9:66ea6fdd3fcb

Merge
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 01:46:25 -0700
parents 5941e6b3684c (current diff) 1bd46f854dbb (diff)
children 370a1eeb8812
files src/sim.tp
diffstat 1 files changed, 57 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sat Jul 14 01:42:05 2012 -0700
+++ b/src/sim.tp	Sat Jul 14 01:46:25 2012 -0700
@@ -11,16 +11,47 @@
 	  }
 	}
 
-	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)
+	cellTypes <- #{
+		allstr <- #[]
+		allobj <- #[]
+		make <- :idstr {
+			ret <- #{
+				id <- (idstr byte: 0)
+			}
+			allobj append: ret
+			allstr append: idstr
+			ret
+		}
+		find <- :idstr {
+			if: idstr = "R" { robot } else: {
+				index <- 0
+				while: { 
+					if: index < (allstr length) { 
+						(allstr get: index) != idstr
+					} else: {false}
+				} do: {
+					index <- index + 1
+				}
+				if: index <- (allstr length) {
+					allobj get: index
+				} else: {
+					empty
+				}
+			}
+		}
+		wall        <- make: "#"
+		empty       <- make: " "
+		earth       <- make: "."
+		rock        <- make: "*"
+		lambda      <- make: "\\"
+		closedlift  <- make: "L"
+		openlift    <- make: "O"
+		newline     <- make: "\n"
+		robot       <- {
+		#{
+			id <- ("R"  byte: 0) 
+			heldBreath <- 0
+		}
     }
 
 	state <- #{
@@ -33,6 +64,7 @@
 				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
@@ -40,15 +72,27 @@
 				getCell <- :x y {
 					grid get: (address: x y)
 				}
+				water <- 0
+				flooding <- 0
+				waterproof <- 10
 				collected <- 0
 				moves <- 0
 				ended <- false
 				doMove <- :roboMove {
+					
+					robo <- doMove r
+					nexty <- doMove y
 					ended <- roboMove = "A"
 				}
-				advance <- :roboMove {
-					doMove: roboMove
+				doUpdate <- {
+					updateCell <- :x, y {
+						if
+					}
+				}
+				advance <- :roboCmd {
+					robot move: roboCmd
 					moves <- moves + 1
+					doUpdate:
 					self
 				}
 				
@@ -61,7 +105,7 @@
 			curRow <- 0
 			while: {index < strLen} do: {
 				curByte <- str byte: index
-				if: curByte = (cellType newline) {
+				if: curByte = (cellType newline id) {
 					maxRow <- if: curRow > maxRow {curRow} else: {maxRow}
 				} else: {
 					curRow = curRow + 1