Mercurial > repos > icfp2012
comparison src/sim.tp @ 52:b0d89ee419c1
Add maximum moves check
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jul 2012 18:37:36 -0700 |
parents | 365c83ea7658 |
children | fbeedb3aa239 |
comparison
equal
deleted
inserted
replaced
50:cf534157ef2f | 52:b0d89ee419c1 |
---|---|
128 state <- #{ | 128 state <- #{ |
129 new <- :in_grid in_width in_height { | 129 new <- :in_grid in_width in_height { |
130 _nextGrid <- #[] | 130 _nextGrid <- #[] |
131 _robot <- null | 131 _robot <- null |
132 _ended <- false | 132 _ended <- false |
133 _maxmoves <- in_width * in_height | |
133 | 134 |
134 _succeeded <- false | 135 _succeeded <- false |
135 ret <- #{ | 136 ret <- #{ |
136 grid <- in_grid | 137 grid <- in_grid |
137 width <- in_width | 138 width <- in_width |
248 grid <- _nextGrid | 249 grid <- _nextGrid |
249 _nextGrid <- tmp | 250 _nextGrid <- tmp |
250 } | 251 } |
251 swapGrids: | 252 swapGrids: |
252 } | 253 } |
254 abort <- { | |
255 _ended <- true | |
256 addPoints: (_robot collected) * 25 | |
257 } | |
253 advance <- :roboCmd { | 258 advance <- :roboCmd { |
254 if: roboCmd = "A" { | 259 if: roboCmd = "A" { |
255 _ended <- true | |
256 moves append: roboCmd | 260 moves append: roboCmd |
257 addPoints: (_robot collected) * 25 | 261 abort |
258 } | 262 } |
259 | 263 |
260 if: (not: _ended) { | 264 if: (not: _ended) { |
261 _robot doCmd: roboCmd | 265 _robot doCmd: roboCmd |
262 score <- score - 1 | 266 score <- score - 1 |
263 moves append: roboCmd | 267 moves append: roboCmd |
264 doUpdate: | 268 doUpdate: |
269 if: (moves length) >= _maxmoves { | |
270 abort | |
271 } | |
265 } | 272 } |
266 self | 273 self |
267 } | 274 } |
268 printGrid <- { | 275 printGrid <- { |
269 cur <- (grid length) - width | 276 cur <- (grid length) - width |