Skip to content

Commit

Permalink
back ECs produce only big pols when safe
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsardana committed Jan 28, 2021
1 parent daa4004 commit 3ee33af
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/jefferson/EnlightmentCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public EnlightmentCenter(RobotController rc) throws GameActionException {
public void run() throws GameActionException {
super.run();

if (currentRound == 600) {
if (currentRound == 1000) {
rc.resign(); // TODO: remove; just for debugging
}

Expand Down Expand Up @@ -403,7 +403,10 @@ else if (numPoliticians > numMuckrakers * poliMuckRatio()) {
else {
//System.out.println("Medium Sized Politician threshold: " + mediumSizedPolitician);
//System.out.println("Diluted Remaining Health:" + dilutedRemainingHealth);
if (Math.random() < 0.5) { // spawn defender
MapLocation tempEnemy = isMidGame ? optimalDestinationMidGame(false) : optimalDestination(false);
boolean allyCloser = existsAllyCloser(tempEnemy);
System.out.println("Only Produce large Politicians: " + (!nearbyMuckraker && allyCloser && currentRound >= 200 && remainingHealth == rc.getConviction()));
if (Math.random() < 0.5 && (nearbyMuckraker || !allyCloser || currentRound < 200 || remainingHealth != rc.getConviction())) { // spawn defender
MapLocation enemyLocation = isMidGame ? optimalDestinationMidGame(false) : optimalDestination(false);
System.out.println("Spawning defender: " + enemyLocation);
int influence = rc.getRoundNum() < 50 ? 14 : 18;
Expand Down Expand Up @@ -506,6 +509,25 @@ MapLocation optimalSlandererDestination() {
} return 1.5;
}

boolean existsAllyCloser(MapLocation enemyLoc) {
int dist2 = myLocation.distanceSquaredTo(enemyLoc);
if (numAllyECs == 0 && capturedAllyECLocsToInfluence.isEmpty()) {
return false;
} else {
for (int i=0; i<numAllyECs; i++) {
if (allyECLocs[i].distanceSquaredTo(enemyLoc) < dist2) {
return true;
}
}
for (MapLocation ml : capturedAllyECLocsToInfluence.keySet()) {
if (ml.distanceSquaredTo(enemyLoc) < dist2) {
return true;
}
}
}
return false;
}

/**
* Reads flags from Ally ECs.
* Handles logic: Given a flag from an Ally EC, what does this EC do?
Expand Down Expand Up @@ -1051,6 +1073,7 @@ MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanc
dArr[1] = vertFurthestDirection == Direction.NORTH ? stop*sendY : -stop*sendY;
} else {
// Randomly launch vertically, horizontally, or at 45 degrees (45 deg TODO).
// System.out.println("randomly launching in all dirs");
int[] dHoriz = optimalHorizontalDestination(horizAbsSum, horizSum, horizFurthestDirection, horizFurthestWall);
int[] dVert = optimalVerticalDestination(vertAbsSum, vertSum, vertFurthestDirection, vertFurthestWall);
double rand = Math.random();
Expand Down

0 comments on commit 3ee33af

Please sign in to comment.