changeset 51:186fce0c98ee

robot can get crushed
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 20:30:46 -0700
parents cf534157ef2f
children a37ceb0a4f5c b2e9e5ad3ad8
files src/sim.tp
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sun Jul 15 18:32:58 2012 -0700
+++ b/src/sim.tp	Sun Jul 15 20:30:46 2012 -0700
@@ -63,7 +63,6 @@
 					collected <- 0
 					heldBreath <- 0
 					razors <- 0
-					busted <- false
 					mine <- null
 					doCmd <- :cmd {
 						action <- commands get: cmd withDefault: { null }
@@ -145,6 +144,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
 				}					
@@ -243,12 +245,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
 				}
 				advance <- :roboCmd {
 					if: roboCmd = "A" {
@@ -262,6 +272,8 @@
 						score <- score - 1
 						moves append: roboCmd
 						doUpdate:
+						checkForDeath:
+						swapGrids:
 					}
 					self
 				}