changeset 34:ac0df071afe7

Start debugging what bill was working on last night. Currently segfautls.
author Mike Pavone <pavone@retrodev.com>
date Sun, 15 Jul 2012 10:30:40 -0700
parents efa82c5e95c2
children 8e8903cc0997
files src/sim.tp
diffstat 1 files changed, 25 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sun Jul 15 03:05:36 2012 -0700
+++ b/src/sim.tp	Sun Jul 15 10:30:40 2012 -0700
@@ -20,8 +20,9 @@
 		new <- :idStr {
 			ret <- #{
 				id <- (idStr byte: 0)
-				str <- idStr
+				string <- idStr
 				isrobot <- { false }
+				eq <- :other { id = (other id) }
 			}
 			typedict set: (ret id) ret
 			ret
@@ -41,19 +42,23 @@
 			openLift    <- new: "O"
 			newline     <- new: "\n"
 			robot       <- {
+				commands <- dict linear
 				ret <- #{
 					id <- ("R"  byte: 0)
-					str <- "R"
+					string <- "R"
 					x <- 0
 					y <- 0
 					isrobot <- { true }
+					eq <- :other { id = (other id) }
 					collected <- 0
 					heldBreath <- 0
 					razors <- 0
 					busted <- false
 					mine <- null
 					doCmd <- :cmd {
+						debugLog: "docmd\n"
 						action <- commands get: cmd
+						debugLog: "fetched action\n"
 						action:
 					}
 					move <- :xDelta yDelta {
@@ -67,22 +72,22 @@
 							y <- yPrime
 						}
 
-						navigable <- {
+						navigable <- :cur {
 							// 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: {
+							if: cur eq empty    {true} else: {
+							if: cur eq earth    {true} else: {
+							if: cur eq lambda   {true} else: {
+							if: cur eq openLift {true} else: {
 							                      false         }}}}
 						}
 						
-						consequenceOf <- {
-							if: self = lambda {collected <- collected + 1}
-							if: self = openLift {mine succeeded!: true}							
+						consequenceOf <- :cur {
+							if: cur = lambda {collected <- collected + 1}
+							if: cur = openLift {mine succeeded!: true}							
 						}
 
 						destination <- mine getCell: xPrime yPrime
-
+						debugLog: "destination is " . destination . "\n"
 						if: (destination navigable: ) {
 							consequenceOf: destination
 							writeMove:
@@ -99,11 +104,10 @@
 
 					}
 				}
-				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: "L" {ret move: (-1)  0  }
+				commands set: "R" {ret move:   1   0  }
+				commands set: "U" {ret move:   0   1  }
+				commands set: "D" {ret move:   0 (-1) }
 				//commands set: "A" {mine ended!: true}
 				ret
 			}
@@ -146,8 +150,10 @@
 				}
 				advance <- :roboCmd {
 					endreached <- roboCmd = "A"
-					robot doCmd: roboCmd inMine: self
+					if: endreached { debugLog: "game over man\n" } else: { debugLog: "still going\n" }
+					robot doCmd: roboCmd
 					moves <- moves + 1
+					debugLog: "calling doUpdate"
 					doUpdate:
 					self
 				}
@@ -155,7 +161,7 @@
 					cur <- (grid length) - width
 					col <- 0
 					while: {cur >= 0} do: {
-						os write: 2 ((grid get: cur) str)
+						os write: 2 ((grid get: cur) string)
 						cur <- cur + 1
 						col <- col + 1
 						if: col = width {
@@ -264,7 +270,7 @@
 			verbose <- true
 			text <- readFile: (args get: 1)
 			print: text
-			os close: 1
+			//os close: 1
 			simState <- state fromStr: text
 			while: { not: (simState ended: ) } do: {
 				simState advance: (getMove: )