From 3b33f2af235f7eab3b5838371a7393d4bb405391 Mon Sep 17 00:00:00 2001 From: "Christopher J. Rogers" Date: Wed, 29 Jan 2014 14:47:09 -0500 Subject: [PATCH] Added a soldierIndex to each soldier which will help in herding and formations --- heinrichTheHerder/RobotPlayer.java | 16 ++++++++-------- heinrichTheHerder/Soldier.java | 23 +++++++---------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/heinrichTheHerder/RobotPlayer.java b/heinrichTheHerder/RobotPlayer.java index cfe09b2..bbba861 100644 --- a/heinrichTheHerder/RobotPlayer.java +++ b/heinrichTheHerder/RobotPlayer.java @@ -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){ @@ -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 { @@ -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; diff --git a/heinrichTheHerder/Soldier.java b/heinrichTheHerder/Soldier.java index 1e73ccd..4487ca2 100644 --- a/heinrichTheHerder/Soldier.java +++ b/heinrichTheHerder/Soldier.java @@ -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); @@ -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; } } \ No newline at end of file