From dcdeced8ca4789132b7253e6fecf2b30b268ff85 Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Fri, 23 Sep 2011 10:30:25 -0700 Subject: [PATCH] -Begin writing Move method for Police Signed-off-by: Tony Grosinger --- bin/net/grosinger/nomads/drones/Police.class | Bin 1717 -> 3384 bytes src/net/grosinger/nomads/drones/Police.java | 91 ++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/bin/net/grosinger/nomads/drones/Police.class b/bin/net/grosinger/nomads/drones/Police.class index 58760b63eb0c4129aeef286b67016a0f5efa2aab..c6ffd1f21fd6c3e4dce913c478d1107898767f71 100644 GIT binary patch literal 3384 zcmbVOX>$}+6g_V;nF&KjAP^*&NZ2%)XhsniK%!(Jj7|cQAuO()OfzYi>5e@;QQY@k zQ4|+cTq(=)ONEX1^XFdyY{9ol#1u9- zmY*qlZpC(rmX~qdvRSBP3ZCm&mCQc3WRF@)nwGbhYU$#jaDy(7o0Q9p@TRRkL z4rF^3YJJx&Rd{PI@>+dgUQ}qYV%)PPY`0qJwLN-kyN<%vXuB|2ZJx6$e%80joBEt; zdBB~p2(_lnwUV=r`dKGGX3s}dS%sA&=IHV2_ zwxmu9w=sxFeuQyrsKs?&f~~kMiCZtD`p^khv~1vZ+`*c-RbQboh}(8E`$$fo6t&Fq zjyh~txH?E_*>qaX5h}O(Zmal|!ky?!VkfzxxqZ2sTLH`dXBrf;1{$zZF1^=44qNE=xIKD&zv&d*@@zke zdxHj+V}(M>v;3;3yMx_5n0L3DXxK0(wDj z&2-7SzYm)%OcY&d!zDO`BS{=q*z(^QVc>oVt#*i&982LrJe>6`N%@Zs1XPlF0FK%i;aaZP~>Q9-@)LWcRYx5O2`+{ILLVLSP<~`bD(- zqN5o&ao~i3C$OGP>bt=xmnfey@HC!LSUPGtGGPyLYU)HCsl#&$tMjgNqN4LD&BGDd zDjHJC7Yw{8C5g*{K)r0>mHAMTggU$y2_iB9dBeb)8bl5RVgi=?)unXRQE=$ z-L_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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; + } } }