# HG changeset patch # User William Morgan # Date 1342409446 25200 # Node ID 186fce0c98ee8d8ed3a6ba605cd93cdda1538ea6 # Parent cf534157ef2f1b008bbce65d51915a453cc98e7c robot can get crushed diff -r cf534157ef2f -r 186fce0c98ee src/sim.tp --- 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 }