# HG changeset patch # User Michael Pavone # Date 1406534591 25200 # Node ID 10a75a37c0fabfb7da4bb82f97cc853bec7fa833 # Parent 91e7a30a9e27d8f5ad87dbe2f94313c37b6761b7 Make ghost2 try to maintain a specific distance in fright mode rather than always running away diff -r 91e7a30a9e27 -r 10a75a37c0fa code/ghost2.gq --- a/code/ghost2.gq Mon Jul 28 00:42:45 2014 -0700 +++ b/code/ghost2.gq Mon Jul 28 01:03:11 2014 -0700 @@ -8,6 +8,9 @@ lastY <- 0 myX <- 0 myY <- 0 + dist <- 0 + distX <- 0 + distY <- 0 getDirX <- :dir startX { if: dir = right { @@ -49,7 +52,7 @@ //ghost is to the right of target if: myY > targetY { //ghost is below target - if: (myX - targetX) > (myY - targetY) { + if: distX > distY { //target is more left than up firstChoice <- left secondChoice <- up @@ -59,7 +62,7 @@ } } else: { //ghost is above or directly to the right of target - if: (myX - targetX) > (targetY - myY) { + if: distX > distY { //target is more left than down firstChoice <- left secondChoice <- down @@ -73,7 +76,7 @@ //ghost is to the left of or directly above/below target if: myY > targetY { //ghost is below target - if: (targetX - myX) > (myY - targetY) { + if: distX > distY { //target is more right than up firstChoice <- right secondChoice <- up @@ -83,7 +86,7 @@ } } else: { //ghost is above or directly to the left of target - if: (targetX - myX) > (targetY - myY) { + if: distX > distY { //target is more right than down firstChoice <- right secondChoice <- down @@ -95,9 +98,11 @@ } } if: myVit = 1 { - //currently in fright mode, try to run away - firstChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice - secondChoice <- (secondChoice + 2) and: 3 //opDir: secondChoice + //currently in fright mode, try to run away if we are close to LM + if: dist < 16 { + firstChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice + secondChoice <- (secondChoice + 2) and: 3 //opDir: secondChoice + } } @@ -133,7 +138,7 @@ } //"wingman" - tries to surround lambda man - //position two cells ahead of his current position + //by picking a position sideways of his current direction main <- { lmX <- lambdamanPos: lmY <- yCoord