diff --git a/RobotPlayer.java b/RobotPlayer.java index 3489c7f..666fdf4 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 * @@ -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; + } } /** @@ -399,4 +429,3 @@ public Tuple(X first, Y second) { } } } -