# HG changeset patch # User Mike Pavone # Date 1342402378 25200 # Node ID cf534157ef2f1b008bbce65d51915a453cc98e7c # Parent 70348843236932a44b5ab77cbb6c0f361a333732# Parent 365c83ea765882cdbacdf963f48d8e9015611914 merge diff -r 703488432369 -r cf534157ef2f maps/testSim0.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim0.map Sun Jul 15 18:32:58 2012 -0700 @@ -0,0 +1,5 @@ +##### +#L R# +#* *# +#* *# +##### diff -r 703488432369 -r cf534157ef2f maps/testSim1.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim1.map Sun Jul 15 18:32:58 2012 -0700 @@ -0,0 +1,24 @@ +##### +#L R# +# *# +# *# +# *# +# *# +# *# +# *# +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +##### + diff -r 703488432369 -r cf534157ef2f maps/testSim2.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim2.map Sun Jul 15 18:32:58 2012 -0700 @@ -0,0 +1,24 @@ +##### +#L R# +# #*# +# #*# +# #*# +# #*# +# #*# +# #*# +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +##### + diff -r 703488432369 -r cf534157ef2f src/sim.tp --- a/src/sim.tp Sun Jul 15 18:12:44 2012 -0700 +++ b/src/sim.tp Sun Jul 15 18:32:58 2012 -0700 @@ -127,9 +127,9 @@ state <- #{ new <- :in_grid in_width in_height { - nextGrid <- #[] + _nextGrid <- #[] _robot <- null - endreached <- false + _ended <- false _succeeded <- false ret <- #{ @@ -139,12 +139,15 @@ calcIndex <- :x y { x + y * width } calcX <- :index {index % width} calcY <- :index {index / width} + getCell <- :x y { + grid get: (calcIndex: x y) + } setCell <- :x y val { grid set: (calcIndex: x y) val } - getCell <- :x y { - grid get: (calcIndex: x y) - } + setNextCell <- :x y val { + _nextGrid set: (calcIndex: x y) val + } validDest?:from <- :index :fromIndex { cell <- (grid get: index) if: (cell navigable) {true} else: { @@ -198,15 +201,16 @@ score <- 0 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 } addPoints <- :points { score <- score + points } - ended <- {endreached} + ended <- {_ended} succeeded <- {_succeeded} succeeded! <- { - endreached <- true + _ended <- true _succeeded <- true addPoints: lambdaCount * 50 } doUpdate <- { foreach: grid :index value { + nextValue <- value if: (value eq: (cellTypes rock)) { x <- calcX: index y <- calcY: index @@ -216,15 +220,15 @@ belowSide <- getCell: (x + delta) (y - 1) if: (side eq: (cellTypes empty)) { if: (belowSide eq: (cellTypes empty)) { - setCell: (x + delta) (y - 1) value - setCell: x y (cellTypes empty) + setNextCell: (x + delta) (y - 1) value + nextValue <- (cellTypes empty) true } else: { false } } else: { false } } if: (below eq: (cellTypes empty)) { - setCell: x y (cellTypes empty) - setCell: x (y - 1) value + nextValue <- (cellTypes empty) + setNextCell: x (y - 1) value } else: { if: (below eq: (cellTypes rock)) { if: (not: (fallToSide: 1)) {fallToSide: -1} } else: { if: (below eq: (cellTypes lambda)) { @@ -233,20 +237,27 @@ } else: { if: (value eq: (cellTypes closedLift)) { if: (_robot collected) = lambdaCount { - grid set: index (cellTypes openLift) + nextValue <- (cellTypes openLift) } } } + _nextGrid set: index nextValue } + swapGrids <- { + tmp <- grid + grid <- _nextGrid + _nextGrid <- tmp + } + swapGrids: } advance <- :roboCmd { if: roboCmd = "A" { - endreached <- true + _ended <- true moves append: roboCmd addPoints: (_robot collected) * 25 } - if: (not: endreached) { + if: (not: _ended) { _robot doCmd: roboCmd score <- score - 1 moves append: roboCmd @@ -299,7 +310,7 @@ } } foreach: in_grid :index el{ - nextGrid append: el + _nextGrid append: el if: (el isrobot) { _robot <- el _robot mine!: ret