changeset 33:efa82c5e95c2

must commit, too late. does not compile.
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 03:05:36 -0700
parents 0a55ee387d69
children ac0df071afe7
files src/sim.tp
diffstat 1 files changed, 80 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sat Jul 14 23:03:04 2012 -0700
+++ b/src/sim.tp	Sun Jul 15 03:05:36 2012 -0700
@@ -1,4 +1,6 @@
 {
+	null <- #{}
+
 	eachbyte <- :string action {
 		strLen <- string byte_length:
 		index <- 0
@@ -35,27 +37,75 @@
 			earth       <- new: "."
 			rock        <- new: "*"
 			lambda      <- new: "\\"
-			closedlift  <- new: "L"
-			openlift    <- new: "O"
+			closedLift  <- new: "L"
+			openLift    <- new: "O"
 			newline     <- new: "\n"
 			robot       <- {
-				#{
+				ret <- #{
 					id <- ("R"  byte: 0)
 					str <- "R"
-					isrobot <- { true }
-					heldBreath <- 0
 					x <- 0
 					y <- 0
-					move <- :cmd mine {
-						writeMove <- :xPrime yPrime {
+					isrobot <- { true }
+					collected <- 0
+					heldBreath <- 0
+					razors <- 0
+					busted <- false
+					mine <- null
+					doCmd <- :cmd {
+						action <- commands get: cmd
+						action:
+					}
+					move <- :xDelta yDelta {
+						xPrime <- x + xDelta
+						yPrime <- y + yDelta
+
+						writeMove <- {
 							mine setCell: xPrime yPrime self
 							mine setCell: x y empty
 							x <- xPrime
 							y <- yPrime
 						}
-						writeMove: x (y + 1)
+
+						navigable <- {
+							// need "any" and "all" functions...
+							if: self = empty    {true} else: {
+							if: self = earth    {true} else: {
+							if: self = lambda   {true} else: {
+							if: self = openLift {true} else: {
+							                      false         }}}}
+						}
+						
+						consequenceOf <- {
+							if: self = lambda {collected <- collected + 1}
+							if: self = openLift {mine succeeded!: true}							
+						}
+
+						destination <- mine getCell: xPrime yPrime
+
+						if: (destination navigable: ) {
+							consequenceOf: destination
+							writeMove:
+						} else: {
+							if: destination = rock {
+								xPrimePrime <- xDelta * 2 + x
+								rockDestination <- mine getCell: xPrimePrime y
+								if: rockDestination = empty {
+									mine setCell: xPrimePrime y rock
+									writeMove:
+								}
+							}
+						}
+
 					}
 				}
+				commands <- dict linear
+				commands set: "L" {move: -1 0 }
+				commands set: "R" {move:  1 0 }
+				commands set: "U" {move: 0  1 }
+				commands set: "D" {move: 0 -1 }
+				//commands set: "A" {mine ended!: true}
+				ret
 			}
 		}
     }
@@ -66,7 +116,7 @@
 	state <- #{
 		new <- :in_grid in_width in_height { 
 			nextGrid <- #[]
-			robot <- false
+			robot <- null
 			endreached <- false
 			ret <- #{
 				grid <- in_grid
@@ -88,15 +138,15 @@
 				water <- 0
 				flooding <- 0
 				waterproof <- 10
-				collected <- 0
 				moves <- 0
 				ended <- {endreached}
+				succeeded <- false
 				doUpdate <- {
 					true
 				}
 				advance <- :roboCmd {
 					endreached <- roboCmd = "A"
-					robot move: roboCmd self
+					robot doCmd: roboCmd inMine: self
 					moves <- moves + 1
 					doUpdate:
 					self
@@ -118,10 +168,27 @@
 			}
 			foreach: in_grid :index el{
 				nextGrid append: el
-				if: (el isrobot) { 
+				if: (el isrobot) {
 					robot <- el
+					robot mine!: ret
 					ret updatePos: robot index
 				}
+
+				  
+//				  adding a 'new' method to robot and doing this instead
+//				  wolud allow me to treat robots and other cellTypes equaly
+//				  particularly for adding methods or state to other cellTypess.
+//
+//				if: (el = (cellTypes robot)) {
+//					robot <- el new:
+//					(ret grid) set: index robot
+//					robot mine!: ret
+//					ret updatePos: robot index
+//					nextGrid append: el
+//				} else: {
+//					nextGrid append: el
+//				}
+
 			}
 			ret
 		}
@@ -136,7 +203,7 @@
 			eachbyte: str :index element {
 				if: element = nl {
 					col <- curline length
-					maxCol <- if: col > maxCol {col} else: {maxCol}					
+					maxCol <- if: col > maxCol {col} else: {maxCol}
 					lines append: curline
 					curline <- #[]
 				} else: {
@@ -161,14 +228,6 @@
 		}
 	}
 
-	testMoves <- {
-		myStep <- 0
-		{
-			myStep <- myStep + 1
-			if: myStep > 5 {"A"} else: {"W"}
-		}
-	}
-	
 	readFd <- :fd {
 		if: fd < 0 { "" } else: {
 			cur <- ""
@@ -207,7 +266,6 @@
 			print: text
 			os close: 1
 			simState <- state fromStr: text
-			derp <- simState ended:
 			while: { not: (simState ended: ) } do: {
 				simState advance: (getMove: )
 				if: verbose {