changeset 50:cf534157ef2f

merge
author Mike Pavone <pavone@retrodev.com>
date Sun, 15 Jul 2012 18:32:58 -0700
parents 703488432369 (current diff) 365c83ea7658 (diff)
children 186fce0c98ee b0d89ee419c1
files
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:32:58 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:32:58 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:32:58 2012 -0700
@@ -0,0 +1,24 @@
+#####
+#L R#
+# #*#
+# #*#
+# #*#
+# #*#
+# #*#
+# #*#
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+# # #
+#####
+
--- 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