# HG changeset patch # User William Morgan # Date 1342401410 25200 # Node ID ccaecf1d64255febd7fcab58f4f288e82b2543d7 # Parent 1f583d85c8ed4f6f067d52485305f3d3c8f5a782 correct reading and writing during update and test maps for verifying that. diff -r 1f583d85c8ed -r ccaecf1d6425 maps/testSim0.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim0.map Sun Jul 15 18:16:50 2012 -0700 @@ -0,0 +1,5 @@ +##### +#L R# +#* *# +#* *# +##### diff -r 1f583d85c8ed -r ccaecf1d6425 maps/testSim1.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim1.map Sun Jul 15 18:16:50 2012 -0700 @@ -0,0 +1,24 @@ +##### +#L R# +# *# +# *# +# *# +# *# +# *# +# *# +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +# # +##### + diff -r 1f583d85c8ed -r ccaecf1d6425 maps/testSim2.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maps/testSim2.map Sun Jul 15 18:16:50 2012 -0700 @@ -0,0 +1,24 @@ +##### +#L R# +# #*# +# #*# +# #*# +# #*# +# #*# +# #*# +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +# # # +##### + diff -r 1f583d85c8ed -r ccaecf1d6425 src/sim.tp --- a/src/sim.tp Sun Jul 15 16:45:42 2012 -0700 +++ b/src/sim.tp Sun Jul 15 18:16:50 2012 -0700 @@ -117,9 +117,9 @@ state <- #{ new <- :in_grid in_width in_height { - nextGrid <- #[] + _nextGrid <- #[] _robot <- null - endreached <- false + _ended <- false _lambdaCount <- 0 _succeeded <- false ret <- #{ @@ -129,12 +129,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: { @@ -185,14 +188,15 @@ flooding <- 0 waterproof <- 10 moves <- 0 - ended <- {endreached} + ended <- {_ended} succeeded <- {_succeeded} succeeded! <- :newval { - endreached <- newval + _ended <- newval _succeeded <- newval } doUpdate <- { foreach: grid :index value { + nextValue <- value if: (value eq: (cellTypes rock)) { x <- calcX: index y <- calcY: index @@ -202,15 +206,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)) { @@ -219,15 +223,22 @@ } 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 { - endreached <- roboCmd = "A" - if: (not: endreached) { + _ended <- roboCmd = "A" + if: (not: _ended) { _robot doCmd: roboCmd moves <- moves + 1 doUpdate: @@ -266,7 +277,7 @@ } } foreach: in_grid :index el{ - nextGrid append: el + _nextGrid append: el if: (el isrobot) { _robot <- el _robot mine!: ret