comparison src/sim.tp @ 51:186fce0c98ee

robot can get crushed
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 20:30:46 -0700
parents 365c83ea7658
children a37ceb0a4f5c b2e9e5ad3ad8
comparison
equal deleted inserted replaced
50:cf534157ef2f 51:186fce0c98ee
61 isrobot <- { true } 61 isrobot <- { true }
62 eq <- :other { id = (other id) } 62 eq <- :other { id = (other id) }
63 collected <- 0 63 collected <- 0
64 heldBreath <- 0 64 heldBreath <- 0
65 razors <- 0 65 razors <- 0
66 busted <- false
67 mine <- null 66 mine <- null
68 doCmd <- :cmd { 67 doCmd <- :cmd {
69 action <- commands get: cmd withDefault: { null } 68 action <- commands get: cmd withDefault: { null }
70 action: 69 action:
71 } 70 }
142 getCell <- :x y { 141 getCell <- :x y {
143 grid get: (calcIndex: x y) 142 grid get: (calcIndex: x y)
144 } 143 }
145 setCell <- :x y val { 144 setCell <- :x y val {
146 grid set: (calcIndex: x y) val 145 grid set: (calcIndex: x y) val
146 }
147 getNextCell <- :x y {
148 _nextGrid get: (calcIndex: x y)
147 } 149 }
148 setNextCell <- :x y val { 150 setNextCell <- :x y val {
149 _nextGrid set: (calcIndex: x y) val 151 _nextGrid set: (calcIndex: x y) val
150 } 152 }
151 validDest?:from <- :index :fromIndex { 153 validDest?:from <- :index :fromIndex {
241 } 243 }
242 } 244 }
243 } 245 }
244 _nextGrid set: index nextValue 246 _nextGrid set: index nextValue
245 } 247 }
246 swapGrids <- { 248 }
247 tmp <- grid 249 checkForDeath <- {
248 grid <- _nextGrid 250 robotsNewFace <- getNextCell: (_robot x) (_robot y) + 1
249 _nextGrid <- tmp 251 robotsFace <- getCell: (_robot x) (_robot y) + 1
250 } 252 if: (robotsNewFace eq: (cellTypes rock)) {
251 swapGrids: 253 if: (not: (robotsFace eq: (cellTypes rock))) {
254 _ended <-true
255 }
256 }
257 }
258 swapGrids <- {
259 tmp <- grid
260 grid <- _nextGrid
261 _nextGrid <- tmp
252 } 262 }
253 advance <- :roboCmd { 263 advance <- :roboCmd {
254 if: roboCmd = "A" { 264 if: roboCmd = "A" {
255 _ended <- true 265 _ended <- true
256 moves append: roboCmd 266 moves append: roboCmd
260 if: (not: _ended) { 270 if: (not: _ended) {
261 _robot doCmd: roboCmd 271 _robot doCmd: roboCmd
262 score <- score - 1 272 score <- score - 1
263 moves append: roboCmd 273 moves append: roboCmd
264 doUpdate: 274 doUpdate:
275 checkForDeath:
276 swapGrids:
265 } 277 }
266 self 278 self
267 } 279 }
268 printGrid <- { 280 printGrid <- {
269 cur <- (grid length) - width 281 cur <- (grid length) - width