Skip to content

Commit

Permalink
sland->pols update base past constructor; mid-game ECs read muck dest…
Browse files Browse the repository at this point in the history
…inations
  • Loading branch information
nikhilsardana committed Jan 28, 2021
1 parent 3ee33af commit fd33a69
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
16 changes: 15 additions & 1 deletion src/jefferson/EnlightmentCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ void readAllyECUpdates() throws GameActionException {
case Flag.SPAWN_DESTINATION_SCHEMA:
if (isMidGame) {
SpawnDestinationFlag sdf = new SpawnDestinationFlag(flagInt);
if (sdf.readInstruction() == SpawnDestinationFlag.INSTR_ATTACK ||
int newInstruction = sdf.readInstruction();
if (newInstruction == SpawnDestinationFlag.INSTR_ATTACK ||
sdf.readInstruction() == SpawnDestinationFlag.INSTR_DEFEND_ATTACK) {
// the robot spawned is going to an enemy, we want to record destination
// so we can use it as a destination for our own robots.
Expand All @@ -569,6 +570,19 @@ void readAllyECUpdates() throws GameActionException {
basesToDestinations.put(allyECIDs[i], new Destination(potentialEnemy, sdf.readGuess()));
System.out.println("Base " + allyECIDs[i] + " told me about a destination " + potentialEnemy);
}
} else if (newInstruction == SpawnDestinationFlag.INSTR_MUCKRAKER) {
MapLocation potentialEnemy = sdf.readAbsoluteLocation(myLocation);
if (!(potentialEnemy.x == myLocation.x && potentialEnemy.y == myLocation.y)) {
if (sdf.readGuess()) {
basesToDestinations.put(allyECIDs[i], new Destination(potentialEnemy, true));
System.out.println("Base " + allyECIDs[i] + " told me about a destination " + potentialEnemy);
} else {
enemyECLocsToInfluence.put(potentialEnemy, 500);
}
}
} else if (newInstruction == SpawnDestinationFlag.INSTR_MUCK_TO_SLAND) {
enemySlanderer = sdf.readAbsoluteLocation(myLocation);
enemySlandererRound = currentRound;
}
}
break;
Expand Down
30 changes: 13 additions & 17 deletions src/jefferson/Politician.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
public class Politician extends Unit {

public final static int INITIAL_COOLDOWN = 10;

boolean convertedPolitician;

// Variables to keep track of defense lap prior to attack for defend-attackers
boolean doLap; // if true, take a lap around base. if false, head for destination.
MapLocation edgeSlanderer; // of the visible slanderers that are farther from the base than I am,
Expand All @@ -23,12 +20,11 @@ public class Politician extends Unit {

boolean[] areSlanderers;
boolean nearbySlanderer;

RobotInfo nearestSlanderer; // Nearest slanderer for considerAttack

public Politician(RobotController rc) throws GameActionException {
super(rc);
convertedPolitician = false;
doLap = true;
defender = false;
foundFirstRing = false;
Expand Down Expand Up @@ -91,7 +87,7 @@ public void runUnit() throws GameActionException {
}
// System.out.println("s (" + i + "): " + Clock.getBytecodesLeft());
}

// System.out.println("2: " + Clock.getBytecodesLeft());
// Converted politician or slanderer turned politician. Set baseLocation and destination.
if (baseLocation == null) {
Expand All @@ -117,7 +113,7 @@ public void runUnit() throws GameActionException {
updateDestinationForExploration(true);
// System.out.println("4: " + Clock.getBytecodesLeft());
updateDestinationForECHunting();

// System.out.println("6: " + Clock.getBytecodesLeft());
considerAttack(true, false);

Expand Down Expand Up @@ -148,7 +144,7 @@ void weakPoliticianTurn() throws GameActionException {
if ((destination == null || nearbyAllies.length > 7) && rc.canEmpower(1)) {
rc.empower(1);
}
// Clogging enemy
// Clogging enemy
else if (myLocation.distanceSquaredTo(destination) <= 2 &&
rc.isLocationOccupied(destination)) {
RobotInfo target = rc.senseRobotAtLocation(destination);
Expand All @@ -168,14 +164,13 @@ else if (myLocation.distanceSquaredTo(destination) <= 2 &&
*/
void setInitialDestination() throws GameActionException {
baseLocation = myLocation;
convertedPolitician = true;
// If enemies nearby, take nearest non-muck non-slanderer as destination
if (nearbyEnemies.length > 0) {
RobotInfo nearestRobot = null;
int nearestRobotDistSquared = 1000;
for (RobotInfo robot : nearbyEnemies) {
int robotDistSquared = myLocation.distanceSquaredTo(robot.location);
if (robot.type != RobotType.SLANDERER && robot.type != RobotType.POLITICIAN &&
if (robot.type != RobotType.SLANDERER && robot.type != RobotType.POLITICIAN &&
robotDistSquared < nearestRobotDistSquared) {
nearestRobot = robot;
nearestRobotDistSquared = robotDistSquared;
Expand All @@ -189,7 +184,7 @@ void setInitialDestination() throws GameActionException {
if (destination == null) {
RobotInfo nearestSignalRobot = getNearestEnemyFromAllies();
// Take nearest smoke signal robot as destination
if (nearestSignalRobot != null && nearestSignalRobot.type != RobotType.SLANDERER
if (nearestSignalRobot != null && nearestSignalRobot.type != RobotType.SLANDERER
&& nearestSignalRobot.type != RobotType.POLITICIAN) {
destination = nearestSignalRobot.location;
}
Expand All @@ -198,6 +193,7 @@ void setInitialDestination() throws GameActionException {
destination = new MapLocation(baseLocation.x + (int)(Math.random()*80 - 40), baseLocation.y + (int)(Math.random()*80 - 40));
}
}
exploreMode = true;
}

/**
Expand Down Expand Up @@ -481,7 +477,7 @@ public int compare(RobotInfo r1, RobotInfo r2) {
// 1 point for if slanderer nearby or not only EC
if (!bigAttacker) {
numEnemiesKilled++;
}
}
// Scaled points for large polis if its a buffraker
else if (robot.conviction > 10) {
numEnemiesKilled += 0.3 + 0.7 * (robot.conviction * 1.0) / (perUnitDamage * 1.0);
Expand All @@ -491,7 +487,7 @@ else if (robot.conviction > 10) {
else if (robot.type == RobotType.ENLIGHTENMENT_CENTER) {
// System.out.println("Can kill EC: " + i + " " + j + " " + robot.location + " " + perUnitDamage + " " + robot.influence + " " + robot.conviction);
numEnemiesKilled += 10;
}
}
// Points for politicians that return net positive influence
else if (robot.type == RobotType.POLITICIAN && multiplier > 2) {
// System.out.println("Can kill PN: " + i + " " + j + " " + robot.location + " " + perUnitDamage + " " + robot.influence + " " + robot.conviction);
Expand Down Expand Up @@ -544,10 +540,10 @@ else if (robot.team != allyTeam && robot.type == RobotType.ENLIGHTENMENT_CENTER)
// ECHunters don't waste on allied units) or adjacent to target
// 3. Either force attack or kill multiple enemies or kill 1 enemy but close to base or slanderers nearby or end of game
if (rc.canEmpower(optimalDist)
&& (nearbyEnemies.length > 0 || optimalNumUnitsHit == 1
|| myLocation.distanceSquaredTo(destination) <= 2 && !destination.equals(baseLocation))
&& (optimalNumEnemiesKilled > 1
|| ((nearbySlanderer || nearbyBase || paranoid || currentRound > 1450) && optimalNumEnemiesKilled > (bigAttacker ? 0.5 : 0))
&& (nearbyEnemies.length > 0 || optimalNumUnitsHit == 1
|| myLocation.distanceSquaredTo(destination) <= 2 && !destination.equals(baseLocation))
&& (optimalNumEnemiesKilled > 1
|| ((nearbySlanderer || nearbyBase || paranoid || currentRound > 1450) && optimalNumEnemiesKilled > (bigAttacker ? 0.5 : 0))
|| (currentRound > 1480 && optimalNumEnemiesKilled > 0))) {
rc.empower(optimalDist);
}
Expand Down
18 changes: 12 additions & 6 deletions src/jefferson/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public void setECSightingFlag() throws GameActionException {
if (allyECLocsToIDs.containsKey(ri.location)) {
allyECLocsToIDs.remove(ri.location);
}
setECSightingFlagHelper(ri.location, enemyTeam, moveThisTurn, ri.influence);
setECSightingFlagHelper(ri.location, enemyTeam, moveThisTurn, ri.influence, ri.ID);
// we may not want to return in the future when there is more computation to be done.
// than just setting a flag.
return;
Expand All @@ -443,7 +443,7 @@ public void setECSightingFlag() throws GameActionException {
if (ri.type == RobotType.ENLIGHTENMENT_CENTER) {
if (!neutralECLocsToIDs.containsKey(ri.location)) {
neutralECLocsToIDs.put(ri.location, ri.ID);
setECSightingFlagHelper(ri.location, neutralTeam, moveThisTurn, ri.influence);
setECSightingFlagHelper(ri.location, neutralTeam, moveThisTurn, ri.influence, ri.ID);
return;
}
}
Expand All @@ -455,18 +455,18 @@ public void setECSightingFlag() throws GameActionException {
allyECLocsToIDs.put(ri.location, ri.ID);
neutralECLocsToIDs.remove(ri.location);
sawNewAllyLastTurn = 1;
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence);
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence, ri.ID);
return;
} else if (enemyECLocsToIDs.containsKey(ri.location)) {
allyECLocsToIDs.put(ri.location, ri.ID);
enemyECLocsToIDs.remove(ri.location);
sawNewAllyLastTurn = 1;
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence);
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence, ri.ID);
return;
} else if (!allyECLocsToIDs.containsKey(ri.location)) {
allyECLocsToIDs.put(ri.location, ri.ID);
sawNewAllyLastTurn = 1;
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence);
setECSightingFlagHelper(ri.location, allyTeam, moveThisTurn, ri.influence, ri.ID);
return;
}
}
Expand All @@ -477,7 +477,13 @@ public void setECSightingFlag() throws GameActionException {
/**
* Helper function to actually set an ECSightingFlag.
*/
public void setECSightingFlagHelper(MapLocation ecLoc, Team t, Direction lastMove, int inf) throws GameActionException {
public void setECSightingFlagHelper(MapLocation ecLoc, Team t, Direction lastMove, int inf, int ecID) throws GameActionException {
if (baseID == 0 && t == allyTeam) {
System.out.println("Former slanderer, setting my base to " + ecID);
baseID = ecID;
baseLocation = ecLoc;
return;
}
int ecType = ECSightingFlag.ENEMY_EC;
if (t == allyTeam) {
ecType = ECSightingFlag.ALLY_EC;
Expand Down

0 comments on commit fd33a69

Please sign in to comment.