# HG changeset patch # User Michael Pavone # Date 1406545118 25200 # Node ID 4251797af36ba59c4b4629ea0067a9f421963c02 # Parent 4438054a183cde539d51af6f96ffe552d425c5b0 Go straight for the fruit diff -r 4438054a183c -r 4251797af36b code/dotScanner.lm --- 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