Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions heinrichTheHerder/RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class RobotPlayer{
static boolean bugLeft;
static boolean panic;
static boolean rush;
static int herderIndex = -1;
static int soldierIndex;
static boolean resetHerding = true;

public static void run(RobotController rc){

Expand Down Expand Up @@ -253,10 +254,11 @@ else if(tunedChannel == Comm.GOOD_NOISE_CHANNEL){

// Soldier is tuned into a squad band
if(Comm.isOnSubchannel(tunedChannel, Comm.SIGN_IN_SUBCHANNEL)) {
if(rc.readBroadcast(tunedChannel) == 0) {
soldierIndex = rc.readBroadcast(tunedChannel);
rc.broadcast(tunedChannel, soldierIndex + 1);
if(soldierIndex == 0) {
// If this squad has no leader, become the leader
isLeader = true;
rc.broadcast(tunedChannel, 1);
tunedChannel = band + Comm.COMMAND_SUBCHANNEL;
rc.broadcast(tunedChannel, Comm.STANDBY);
} else {
Expand Down Expand Up @@ -358,12 +360,10 @@ else if(tunedChannel == Comm.GOOD_NOISE_CHANNEL){
int channelData = rc.readBroadcast(band + Comm.LEADER_LOCATION_SUBCHANNEL);
int command = rc.readBroadcast(band + Comm.COMMAND_SUBCHANNEL);
if(command == Comm.HERD) {
if(herderIndex == -1) {
herderIndex = Soldier.getHerderIndex(rc, band);
}
Soldier.herdCows(rc, band, random, herderIndex);
int herderIndex = soldierIndex - 1;
Soldier.herdCows(rc, band, random, herderIndex, resetHerding);
} else {
herderIndex = -1;
resetHerding = true;
// Follow the leader
if(channelData > 10100){
channelData -= 10100;
Expand Down
23 changes: 7 additions & 16 deletions heinrichTheHerder/Soldier.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,13 @@ public static boolean isAtLocation(RobotController rc, MapLocation location, boo
}
}

public static void herdCows(RobotController rc, int band, Random random, int herderIndex) throws GameActionException {
public static void herdCows(RobotController rc, int band, Random random, int herderIndex, boolean resetHerding) throws GameActionException {
MapLocation pastrLocation = VectorActions.intToLoc(rc.readBroadcast(band + Comm.LOCATION_SUBCHANNEL));
if(resetHerding) {
Soldier.currentHerdingStatus = herdingStatus.init;
RobotPlayer.resetHerding = false;
}

if(herderIndex >= 0 && herderIndex <= 7) {
MapLocation startingLocation = pastrLocation.add(Direction.values()[herderIndex], 3);
TerrainTile tileAtStart = rc.senseTerrainTile(startingLocation);
Expand Down Expand Up @@ -435,23 +440,9 @@ public static void herdCows(RobotController rc, int band, Random random, int her
Soldier.moveToLocation(rc, startingLocation, random, false);
}
}
} else if(herderIndex == 8){
} else {
// Sneak around PASTR
Soldier.moveToLocation(rc, pastrLocation, random, true);
} else {
System.out.println("Shouldn't be here");
}
}

public static int getHerderIndex(RobotController rc, int band) throws GameActionException {
int herdingRootChannel = band + Comm.HERDER_ROOT_SUBCHANNEL;
for(int i = 0; i < 8; i++) {
if(rc.readBroadcast(herdingRootChannel + i) == 0) {
rc.broadcast(herdingRootChannel + i, 1);
Soldier.currentHerdingStatus = herdingStatus.init;
return i;
}
}
return 8;
}
}