changeset 47:ccaecf1d6425

correct reading and writing during update and test maps for verifying that.
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 18:16:50 -0700
parents 1f583d85c8ed
children 365c83ea7658
files maps/testSim0.map maps/testSim1.map maps/testSim2.map src/sim.tp
diffstat 4 files changed, 79 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- /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#
+#* *#
+#* *#
+#####
--- /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#
+#  *#
+#  *#
+#  *#
+#  *#
+#  *#
+#  *#
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#####
+
--- /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#
+# #*#
+# #*#
+# #*#
+# #*#
+# #*#
+# #*#
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+#####
+
--- 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