Skip to content
69 changes: 67 additions & 2 deletions RobotPlayer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zobomb; //So the program knows what to call our bot
package zombomb; //So the program knows what to call our bot

import battlecode.common.*; //imports Battlecode UI
import java.util.Random; //Use this instead of Math.random(); seeded by the robot's id so more likely to be random than Math.random
Expand All @@ -9,9 +9,14 @@ 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;
static Team ourTeam;
static Team opponentTeam;

/**
* run
Expand All @@ -25,6 +30,14 @@ public static void run(RobotController r){
rc = r;
randall = new Random(rc.getID());
RobotType selftype = rc.getType();
if(rc.getTeam() ==Team.A) {
ourTeam = Team.A;
opponentTeam = Team.B;
}
if(rc.getTeam() == Team.B) {
ourTeam = Team.B;
opponentTeam = Team.A;
}
if(selftype == RobotType.ARCHON){
Archon s = new RobotPlayer().new Archon();
s.run();
Expand Down Expand Up @@ -206,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
*
Expand Down Expand Up @@ -347,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<Integer,Integer> 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;
}
}

/**
Expand All @@ -363,4 +429,3 @@ public Tuple(X first, Y second) {
}
}
}