changeset 79:dcfa97976071

Better handling of target selection
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 03:24:21 -0700
parents 3b8a277decfa
children 4438054a183c
files code/dotScanner.lm
diffstat 1 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/code/dotScanner.lm	Mon Jul 28 03:11:01 2014 -0700
+++ b/code/dotScanner.lm	Mon Jul 28 03:24:21 2014 -0700
@@ -35,6 +35,7 @@
 	visited <- 0
 	badGhostCount <- 0
 	edibleGhosts <- 0
+	totalGhosts <- 0
 
 	advancer <- :continuations {
 		notdone <- 1
@@ -66,6 +67,11 @@
 		}
 		continuations
 	}
+	
+	target0 <- 2
+	target1 <- 3
+	target2 <- 4
+	target3 <- 7
 
 	makeContClos <- :grid myLoc path {
 		{
@@ -76,20 +82,7 @@
 				if: (grid: visited get: myLoc) {
 				} else: {
 					atpos <- grid: grid get: myLoc
-					if: badGhostCount > 0 {
-					} else: {
-						//treat power pellets as empty space when there are no ghosts in normal mode
-						if: (atpos = 3) {
-							atpos <- 1
-						} else: {
-							if: edibleGhosts > 0 {
-								if: (atpos = 2) {
-									atpos <- 1
-								} else: {}
-							} else: {}
-						}
-					}
-					if: (atpos = 2) + (atpos = 3) + (atpos = 4) + (atpos = 7) {
+					if: (atpos = target0) + (atpos = target1) + (atpos = target2) + (atpos = target3) {
 						//pellet, power pellet, fruit
 						ret <- #[1 (reverse: path)]
 					} else: {
@@ -133,7 +126,9 @@
 		})
 		badGhostCount <- 0
 		edibleGhosts <- 0
+		totalGhosts <- 0
 		grid <- fold: ghostState grid with: :acc ghost {
+			totalGhosts <- totalGhosts + 1
 			vitality <- ghost value
 			loc <- (ghost tail) value
 			dir <- (ghost tail) tail
@@ -179,6 +174,24 @@
 			}
 			acc
 		}
+		//default behavior, target all yummy things
+		target0 <- 2
+		target1 <- 3
+		target2 <- 4
+		target3 <- 7
+		if: badGhostCount > 0 {
+		} else: {
+			if: totalGhosts > 0 {
+				//ignore power pellets when there are no ghosts in normal mode
+				target1 <- 2
+				if: edibleGhosts > 0 {
+					//ignore anything except edible ghosts when some are in range
+					target0 <- 7
+					target1 <- 7
+					target2 <- 7
+				} 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 {