Mercurial > repos > icfp2012
comparison src/sim.tp @ 56:ca86c88c2336
merge
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sun, 15 Jul 2012 22:24:35 -0700 |
parents | b2e9e5ad3ad8 a37ceb0a4f5c |
children | aa822c683e28 |
comparison
equal
deleted
inserted
replaced
55:b2e9e5ad3ad8 | 56:ca86c88c2336 |
---|---|
57 id <- ("R" byte: 0) | 57 id <- ("R" byte: 0) |
58 string <- "R" | 58 string <- "R" |
59 x <- 0 | 59 x <- 0 |
60 y <- 0 | 60 y <- 0 |
61 isrobot <- { true } | 61 isrobot <- { true } |
62 navigable <- { false } | |
62 eq <- :other { id = (other id) } | 63 eq <- :other { id = (other id) } |
63 collected <- 0 | 64 collected <- 0 |
64 heldBreath <- 0 | 65 heldBreath <- 0 |
65 razors <- 0 | 66 razors <- 0 |
66 mine <- null | 67 mine <- null |
127 state <- #{ | 128 state <- #{ |
128 new <- :in_grid in_width in_height { | 129 new <- :in_grid in_width in_height { |
129 _nextGrid <- #[] | 130 _nextGrid <- #[] |
130 _robot <- null | 131 _robot <- null |
131 _ended <- false | 132 _ended <- false |
133 _maxmoves <- in_width * in_height | |
134 _heuristicValid <- false | |
135 _heuristic <- 0 | |
132 getSafe <- :collection :index { | 136 getSafe <- :collection :index { |
133 if: index >= 0 { | 137 if: index >= 0 { |
134 if: index < (collection length) { | 138 if: index < (collection length) { |
135 collection get: index | 139 collection get: index |
136 } else: { (cellTypes wall) } | 140 } else: { (cellTypes wall) } |
194 cur append: el | 198 cur append: el |
195 } | 199 } |
196 } | 200 } |
197 cur | 201 cur |
198 } | 202 } |
203 distanceFrom:to <- :x y celltype { | |
204 //print: "calculating distance from " . x . ", " . y . " to " . celltype . "\n" | |
205 moves <- validMoves: x y | |
206 curdist <- 0 | |
207 visited <- _nextGrid | |
208 foreach: grid :idx el { | |
209 visited set: idx false | |
210 } | |
211 notfound <- true | |
212 while: { if: notfound { (moves length) > 0 } } do: { | |
213 nextmoves <- #[] | |
214 curdist <- curdist + 1 | |
215 foreach: moves :idx move { | |
216 curpos <- move index | |
217 if: (not: (visited get: curpos)) { | |
218 if: ((grid get: curpos) eq: celltype) { | |
219 notfound <- false | |
220 } else: { | |
221 visited set: curpos true | |
222 foreach: (validMoves: (calcX: curpos) (calcY: curpos)) :idx move { | |
223 nextmoves append: move | |
224 } | |
225 } | |
226 } | |
227 } | |
228 moves <- nextmoves | |
229 } | |
230 curdist | |
231 } | |
199 getRobot <- { _robot } | 232 getRobot <- { _robot } |
200 updatePos <- :obj Index { | 233 updatePos <- :obj Index { |
201 obj x!: (calcX: Index) | 234 obj x!: (calcX: Index) |
202 obj y!: (calcY: Index) | 235 obj y!: (calcY: Index) |
203 } | 236 } |
206 flooding <- 0 | 239 flooding <- 0 |
207 waterproof <- 10 | 240 waterproof <- 10 |
208 moves <- #[] | 241 moves <- #[] |
209 score <- 0 | 242 score <- 0 |
210 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 } | 243 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 } |
244 heuristic <- { | |
245 if: (not: _heuristicValid) { | |
246 dest <- if: (_robot collected) = lambdaCount { | |
247 cellTypes openLift | |
248 } else: { | |
249 cellTypes lambda | |
250 } | |
251 _heuristic <- score - (distanceFrom: (_robot x) (_robot y) to: dest) | |
252 _heuristicValid <- true | |
253 } | |
254 _heuristic | |
255 } | |
211 addPoints <- :points { score <- score + points } | 256 addPoints <- :points { score <- score + points } |
212 ended <- {_ended} | 257 ended <- {_ended} |
213 succeeded <- {_succeeded} | 258 succeeded <- {_succeeded} |
214 succeeded! <- { | 259 succeeded! <- { |
215 _ended <- true | 260 _ended <- true |
264 swapGrids <- { | 309 swapGrids <- { |
265 tmp <- grid | 310 tmp <- grid |
266 grid <- _nextGrid | 311 grid <- _nextGrid |
267 _nextGrid <- tmp | 312 _nextGrid <- tmp |
268 } | 313 } |
314 abort <- { | |
315 _ended <- true | |
316 addPoints: (_robot collected) * 25 | |
317 } | |
269 advance <- :roboCmd { | 318 advance <- :roboCmd { |
319 _heuristicValid <- false | |
270 if: roboCmd = "A" { | 320 if: roboCmd = "A" { |
271 _ended <- true | |
272 moves append: roboCmd | 321 moves append: roboCmd |
273 addPoints: (_robot collected) * 25 | 322 abort |
274 } | 323 } |
275 | 324 |
276 if: (not: _ended) { | 325 if: (not: _ended) { |
277 _robot doCmd: roboCmd | 326 _robot doCmd: roboCmd |
278 score <- score - 1 | 327 score <- score - 1 |
279 moves append: roboCmd | 328 moves append: roboCmd |
280 doUpdate: | 329 doUpdate: |
281 checkForDeath: | 330 checkForDeath: |
282 swapGrids: | 331 swapGrids: |
332 if: (moves length) >= _maxmoves { | |
333 abort | |
334 } | |
283 } | 335 } |
284 self | 336 self |
285 } | 337 } |
286 printGrid <- { | 338 printGrid <- { |
287 cur <- (grid length) - width | 339 cur <- (grid length) - width |