changeset 40:f38437d22ebd

success is possible. W implemented. Rock movement started but not finished.
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 14:35:56 -0700
parents 2dc785f67327
children 20327ae2120b
files src/sim.tp
diffstat 1 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/sim.tp	Sun Jul 15 13:06:58 2012 -0700
+++ b/src/sim.tp	Sun Jul 15 14:35:56 2012 -0700
@@ -28,7 +28,7 @@
 				string <- idStr
 				isrobot <- { false }
 				eq <- :other { id = (other id) }
-				navigable <- { cannav }
+				navigable <- { cannav }				
 			}
 			typedict set: (ret id) ret
 			ret
@@ -62,7 +62,7 @@
 					busted <- false
 					mine <- null
 					doCmd <- :cmd {
-						action <- commands get: cmd
+						action <- commands get: cmd withDefault: { null }
 						action:
 					}
 					move <- :xDelta yDelta {
@@ -116,6 +116,8 @@
 			nextGrid <- #[]
 			robot <- null
 			endreached <- false
+			_lambdaCount <- 0
+			_succeeded <- false
 			ret <- #{
 				grid <- in_grid
 				width <- in_width
@@ -133,14 +135,35 @@
 					obj x!: (calcX: Index)
 					obj y!: (calcY: Index)
 				}
+				lambdaCount <- {_lambdaCount}
 				water <- 0
 				flooding <- 0
 				waterproof <- 10
 				moves <- 0
 				ended <- {endreached}
-				succeeded <- false
+				succeeded <- {_succeeded}
+				succeeded! <- :newval {
+					endreached <- newval
+					_succeeded <- newval
+				}
 				doUpdate <- {
-					true
+					foreach: grid :index value {
+						if: (value eq: (cellTypes rock)) {
+							x <- calcX: index
+							y <- calcY: index
+							below <- getCell: x (y - 1)
+							if: (below eq: (cellTypes empty)) {
+								setCell: x y (cellTypes empty)
+								setCell: x (y - 1) value
+							}
+						} else: {
+							if: (value eq: (cellTypes closedLift)) {
+								if: (robot collected) = _lambdaCount {
+									grid set: index (cellTypes openLift)
+								}
+							}
+						}
+					}
 				}
 				advance <- :roboCmd {
 					endreached <- roboCmd = "A"
@@ -172,6 +195,10 @@
 					robot <- el
 					robot mine!: ret
 					ret updatePos: robot index
+				} else: { 
+					if: (el eq: (cellTypes lambda)) {
+						_lambdaCount <- _lambdaCount + 1
+					}
 				}