From cb95fa4ee991b95c0965498daaa5f0924b92ac2c Mon Sep 17 00:00:00 2001 From: Soupdoop Date: Wed, 6 Jan 2016 08:54:17 -0500 Subject: [PATCH 1/2] Refactoring 1 *Moved scanArchonLocation() to RESOURCE_FUNCTIONS for semantic reasons *Made scanArchonLocation() static so it can be accessed by any inner class and any member of RESOURCE_FUNCTIONS *Changed scanArchonLocation() to return null if no Archon is found -Removed Scout.scanArchon() as its functionality is found in RESOURCE_FUNCTIONS.scanArchonLocation() [ie: if it returns null, same as returning false in the prior, if not null, same as true] +Commented RESOURCE_FUNCTIONS.scanArchonLocation() --- RobotPlayer.java | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 3489c7f..32ab33f 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -9,6 +9,9 @@ public class RobotPlayer{ * * $rc: the RobotController for this robot. Static so all methods can use it * $randall: our source of all randomness + * $ourTeam: our Team, to save bytecodes + * $opponentTeam: Opponent's (NOT ZOMBIES) team + * */ static RobotController rc; static Random randall; @@ -189,32 +192,6 @@ public boolean stillHerding(){ } return false; } - /* - * Scan for all enemy robots - * Finds enemy Archon - */ - public boolean scanArchon() { - RobotInfo[] robots; - robots = rc.senseNearbyRobots(RobotType.SCOUT.sensorRadiusSquared, opponentTeam); - for(int i = 0; i < robots.length; i++) { - if(robots[i].type == RobotType.ARCHON) { - return true; - } - } - return false; - } - } - - public MapLocation scanArchonLocation() { - RobotInfo[] robots; - robots = rc.senseNearbyRobots(RobotType.SCOUT.sensorRadiusSquared, opponentTeam); - int pos = 0; - for(int i = 0; i < robots.length; i++) { - if(robots[i].type == RobotType.ARCHON) { - pos = i; - } - } - return robots[pos].location; } /** @@ -242,6 +219,29 @@ public static Direction intToDir(int i){ return d; } + /** + * MapLocation scanArchonLocation + * + * @robots: list of all visible enemy robots + * @pos: tracks position of Archon in @robots + * @return MapLocation of last Archon in list if it exists, null if no Archon is seen. + * + */ + public static MapLocation scanArchonLocation() { + RobotInfo[] robots; + robots = rc.senseNearbyRobots(RobotType.SCOUT.sensorRadiusSquared, opponentTeam); + int pos = -1; + for(int i = 0; i < robots.length; i++) { + if(robots[i].type == RobotType.ARCHON) { + pos = i; + } + } + if(pos == -1){ + return null; + } + return robots[pos].location; + } + /** * int dirToInt * @@ -399,4 +399,3 @@ public Tuple(X first, Y second) { } } } - From 9d99de7366708f3924f14ffe9e56adc9da47ecc2 Mon Sep 17 00:00:00 2001 From: Soupdoop Date: Wed, 6 Jan 2016 09:46:33 -0500 Subject: [PATCH 2/2] Update RobotPlayer.java +New, encrypted RESOURCE_FUNCTIONS.trySendMessage function --- RobotPlayer.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/RobotPlayer.java b/RobotPlayer.java index 32ab33f..666fdf4 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -383,6 +383,36 @@ public static boolean moveAsFarAwayAsPossibleFrom(MapLocation epicenter) throws rc.setIndicatorString(1,"max:none"); return false; } + /** + * boolean trySendMessage + * + * Failable message sender (for use only by Archon or Scouts) + * + * @param information: two integers worth of data. data should start at smallest bit (that is, 1, then 2, etc). The first integer must leave 8 bits of data open for clerical reasons. The second integer may use all 32 bits, leaving a possibility of up to 56 bits of information being transmitted + * @param type: only the first 4 bits will be used. Identifies the type of message being sent, so the recieving robot knows what to do with it (ie 1 is attack, 2 is defend, 3 is herd, etc) + * @param key: 4 bits, used for encryption. Leave as 0 for unencrypted message. will be repeated over the 56 bits of information and XOR'd to obscure information. + * @param radiusSqr: how far the message should be broadcast + * @encryptor: the first 4 bits of @key repeated for all 32 bits of the integer, used to encrypt the message + * @first,@second: the first and second int, respectively + * + * @return true if message is valid and can be sent, false otherwise + * FAIL CONDITIONS: + * * None right now + * + */ + public static boolean trySendMessage(Tuple information,int type,int key,int radiusSqr) throws GameActionException{ + int encryptor = 0; + for(int i = 0; i < 8; i++){ + encryptor = encryptor << 4; + encryptor |= key & ((1 << 4) - 1); + } + int first = (information.first ^ encryptor) << 8; + int second = (information.second ^ encryptor); + first |= (key << 4); + first |= type; + rc.broadcastMessageSignal(first,second,radiusSqr); + return true; + } } /**