changeset 54:a37ceb0a4f5c

merge
author Mike Pavone <pavone@retrodev.com>
date Sun, 15 Jul 2012 21:56:43 -0700
parents fbeedb3aa239 (current diff) 186fce0c98ee (diff)
children ca86c88c2336 397089dccb32
files src/sim.tp
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sun Jul 15 21:42:46 2012 -0700
+++ b/src/sim.tp	Sun Jul 15 21:56:43 2012 -0700
@@ -64,7 +64,6 @@
 					collected <- 0
 					heldBreath <- 0
 					razors <- 0
-					busted <- false
 					mine <- null
 					doCmd <- :cmd {
 						action <- commands get: cmd withDefault: { null }
@@ -148,6 +147,9 @@
 				setCell <- :x y val {
 					grid set: (calcIndex: x y) val
 				}
+				getNextCell <- :x y {
+					_nextGrid get: (calcIndex: x y)
+				}
 				setNextCell <- :x y val {
 					_nextGrid set: (calcIndex: x y) val
 				}					
@@ -287,12 +289,20 @@
 						}
 						_nextGrid set: index nextValue
 					}
-					swapGrids <- {
-						tmp <- grid
-						grid <- _nextGrid
-						_nextGrid <- tmp
+				}
+				checkForDeath <- {
+					robotsNewFace <- getNextCell: (_robot x) (_robot y) + 1
+					robotsFace    <- getCell:     (_robot x) (_robot y) + 1
+					if: (robotsNewFace eq: (cellTypes rock)) {
+						if: (not: (robotsFace eq: (cellTypes rock))) {
+							_ended <-true
+						}
 					}
-					swapGrids:
+				}
+				swapGrids <- {
+					tmp <- grid
+					grid <- _nextGrid
+					_nextGrid <- tmp
 				}
 				abort <- {
 					_ended <- true
@@ -310,6 +320,8 @@
 						score <- score - 1
 						moves append: roboCmd
 						doUpdate:
+						checkForDeath:
+						swapGrids:
 						if: (moves length) >= _maxmoves {
 							abort
 						}