changeset 65:aa822c683e28

merge
author Mike Pavone <pavone@retrodev.com>
date Mon, 16 Jul 2012 04:35:43 -0700
parents 3d058b4889a2 (current diff) ca86c88c2336 (diff)
children cffcf36f1610
files src/sim.tp
diffstat 6 files changed, 56 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/maps/evilbug1.map	Mon Jul 16 04:35:43 2012 -0700
@@ -0,0 +1,6 @@
+###R#
+#   #
+#   #
+L   #
+#####
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/maps/evilbug2.map	Mon Jul 16 04:35:43 2012 -0700
@@ -0,0 +1,5 @@
+#####
+#  R#
+#   #
+*# #*
+*#L#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/maps/evilbug3.map	Mon Jul 16 04:35:43 2012 -0700
@@ -0,0 +1,6 @@
+#####
+#  R#
+#   #
+*# #*
+*#L#*
+#####
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/maps/evilbug4.map	Mon Jul 16 04:35:43 2012 -0700
@@ -0,0 +1,3 @@
+#  R#
+*# #*
+*#L#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/maps/testSim3.map	Mon Jul 16 04:35:43 2012 -0700
@@ -0,0 +1,24 @@
+#####
+#L  #
+#  *#
+#  *#
+#  *#
+#  *#
+#  *#
+#  *#
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#   #
+#  R#
+#####
+
--- a/src/sim.tp	Mon Jul 16 04:35:24 2012 -0700
+++ b/src/sim.tp	Mon Jul 16 04:35:43 2012 -0700
@@ -133,6 +133,13 @@
 			_maxmoves <- in_width * in_height
 			_heuristicValid <- false
 			_heuristic <- 0
+			getSafe <- :collection :index {
+				if: index >= 0 {
+					if: index < (collection length) {
+						collection get: index
+					} else: { (cellTypes wall) }
+				} else: { (cellTypes wall) }
+			}			
 			_succeeded <- false
 			ret <- #{
 				grid <- in_grid
@@ -142,26 +149,26 @@
 				calcX <- :index {index % width}
 				calcY <- :index {index / width}
 				getCell <- :x y {
-					grid get: (calcIndex: x y)
+					grid getSafe: (calcIndex: x y)
 				}
 				setCell <- :x y val {
 					grid set: (calcIndex: x y) val
 				}
 				getNextCell <- :x y {
-					_nextGrid get: (calcIndex: x y)
+					_nextGrid getSafe: (calcIndex: x y)
 				}
 				setNextCell <- :x y val {
 					_nextGrid set: (calcIndex: x y) val
 				}					
 				validDest?:from <- :index :fromIndex {
-					cell <- (grid get: index)
+					cell <- (grid getSafe: index)
 					if: (cell navigable) {true} else: {
 						if: (cell eq: (cellTypes rock)) {
 							diff <- index - fromIndex
 							//make sure movement was horizontal
 							if: (abs: diff) = 1 {
 								rockdest <- index + diff
-								if: ((grid get: rockdest) eq: (cellTypes empty)) {
+								if: ((grid getSafe: rockdest) eq: (cellTypes empty)) {
 									//make sure rock destination doesn't wrap
 									(calcY: rockdest) = (calcY: index)
 								}
@@ -377,7 +384,7 @@
 					cur <- (grid length) - width
 					col <- 0
 					while: {cur >= 0} do: {
-						os write: 2 ((grid get: cur) string)
+						os write: 2 ((grid getSafe: cur) string)
 						cur <- cur + 1
 						col <- col + 1
 						if: col = width {