diff --git a/bin/net/grosinger/nomads/drones/Police.class b/bin/net/grosinger/nomads/drones/Police.class index 58760b6..c6ffd1f 100644 Binary files a/bin/net/grosinger/nomads/drones/Police.class and b/bin/net/grosinger/nomads/drones/Police.class differ diff --git a/src/net/grosinger/nomads/drones/Police.java b/src/net/grosinger/nomads/drones/Police.java index 3ac6a1d..9faa3ff 100644 --- a/src/net/grosinger/nomads/drones/Police.java +++ b/src/net/grosinger/nomads/drones/Police.java @@ -1,6 +1,7 @@ package net.grosinger.nomads.drones; import net.grosinger.nomads.DroneTools; +import net.grosinger.nomads.Point; import net.grosinger.nomads.drones.DroneListItem.EnumMove; /** @@ -19,13 +20,20 @@ public class Police implements Drone { private static final boolean DEBUGGINGALL = true; - // Do not change these + // Do not change these // private String name; private String UID; - // Define any variables that you need + // Define any variables that you need // private DroneTools tools; + // Moving Related + private EnumMove previousDirection; + private int movesLeftInThisDirection; + private static Point backupRequestedHere; + + private Point iAmGoingToGiveBackup; + // Leave these methods alone, they are required // @Override @@ -60,6 +68,32 @@ public class Police implements Drone { if (DEBUGGINGALL) { System.out.println("Policeman about to move"); } + + if (iAmGoingToGiveBackup != null) { + // If I am not at this point already, go there + + // If I am at that point, unset the variable and start looking for + // people + } else if (backupRequestedHere != null) { + // Another policeman needs backup, go there + EnumMove returnThis = goToPoint(backupRequestedHere); + + // Remove the request for backup + backupRequestedHere = null; + return returnThis; + } else if (movesLeftInThisDirection == 0) { + // If I am not going anywhere specific, just pick a random + // direction, travel that way for 3 moves, then repeat + movesLeftInThisDirection = 2; + previousDirection = pickRandomDirection(); + return previousDirection; + } else if (movesLeftInThisDirection > 0) { + // If I am not going anywhere specific, just pick a random + // direction, travel that way for 3 moves, then repeat + movesLeftInThisDirection--; + return previousDirection; + } + // A police drone will move semi-randomly, looking for neighbors. // Upon finding neighbors it will scan them to see if any of them are // wanted. If one is wanted it will start to pursue them and attempt to @@ -83,7 +117,58 @@ public class Police implements Drone { return null; } - public void requestBackup() { + public void requestBackup(Point goHere) { + backupRequestedHere = goHere; + } + /** + * Chooses a random direction to travel from North, South, East, and West + * + * @return EnumMove + */ + private EnumMove pickRandomDirection() { + // TODO - Implement pickRandomDirection + return EnumMove.South; + } + + /** + * Will travel East/West then North/South to get to the point provided + * + * @param goHere + * Point that is to be traveled to + * @return EnumMove that is to be given to move method + */ + private EnumMove goToPoint(Point goHere) { + int amountN = tools.getY() - goHere.getY(); + int amountE = tools.getX() - goHere.getX(); + + if (DEBUGGINGALL) { + System.out.println("Amount East: " + amountE + " Amount North: " + amountN); + } + + // TODO - Find out why this isn't working + if (amountE > 0 && tools.canMoveWest()) { + if (DEBUGGINGALL) { + System.out.println("TonysDrone moving West"); + } + return EnumMove.West; + } else if (amountE < 0 && tools.canMoveEast()) { + if (DEBUGGINGALL) { + System.out.println("TonysDrone moving East"); + } + return EnumMove.East; + } else if (amountN > 0 && tools.canMoveNorth()) { + if (DEBUGGINGALL) { + System.out.println("TonysDrone moving North"); + } + return EnumMove.North; + } else if (amountN < 0 && tools.canMoveSouth()) { + if (DEBUGGINGALL) { + System.out.println("TonysDrone moving South"); + } + return EnumMove.South; + } else { + return EnumMove.NoMove; + } } }