changeset 81:4251797af36b

Go straight for the fruit
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 03:58:38 -0700
parents 4438054a183c
children ea6a0709373f
files code/dotScanner.lm
diffstat 1 files changed, 40 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/code/dotScanner.lm	Mon Jul 28 03:25:05 2014 -0700
+++ b/code/dotScanner.lm	Mon Jul 28 03:58:38 2014 -0700
@@ -103,6 +103,9 @@
 			ret
 		}
 	}
+	
+	fruitX <- 0
+	fruitY <- 0
 
 	step <- :myState world {
 		lmState <- (world tail) value
@@ -112,16 +115,6 @@
 		fruitState <- ((world tail) tail) tail
 		
 		grid <- makeTree: (map: (world value) :row { 
-			if: fruitState >= 127 {
-			} else: {
-				row <- map: row :el {
-					//remove fruit if it is not enabled
-					if: el = 4 {
-						el <- 1
-					} else: {}
-					el
-				}
-			}
 			makeTree: row 
 		})
 		badGhostCount <- 0
@@ -177,7 +170,12 @@
 		//default behavior, target all yummy things
 		target0 <- 2
 		target1 <- 3
-		target2 <- 4
+		if: fruitState > 0 {
+			//only target fruit when it is actually present
+			target2 <- 4
+		} else: {
+			target2 <- 2
+		}
 		target3 <- 7
 		if: badGhostCount > 0 {
 		} else: {
@@ -192,6 +190,26 @@
 				} else: {}
 			} else: {}
 		}
+		fruitDist <- 0
+		if: target2 = 4 {
+			if: (myLoc value) > fruitX {
+				fruitDist <- (myLoc value) - fruitX
+			} else: {
+				fruitDist <-  fruitX - (myLoc value)
+			}
+			if: (myLoc tail) > fruitY {
+				fruitDist <- fruitDist + (myLoc tail) - fruitY
+			} else: {
+				fruitDist <-  fruitDist + fruitY - (myLoc tail)
+			}
+			if: fruitState > (fruitDist * 127) {
+				//go straight for the fruit if we can make it in time
+				target0 <- 4
+				target1 <- 4
+				target2 <- 4
+				target3 <- 4
+			} else: {}
+		} else: {}
 		//make sure my location is marked clear even if there is a ghost nearby
 		grid <- grid: grid set: myLoc to: 1
 		visited <- treeMap: grid :row {
@@ -206,6 +224,17 @@
 	}
 	
 	main <- :initWorld ghostCode {
+		grid <- (initWorld) value
+		fold: grid 0 with: :y row {
+			fold: row 0 with: :x el {
+				if: el = 4 {
+					fruitX <- x
+					fruitY <- y
+				} else: {}
+				x + 1
+			}
+			y + 1
+		}
 		/*
 		print: (step: 0 #[
 			//grid