Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mvpatel2000/Battlecode2021 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mvpatel2000 committed Jan 28, 2021
2 parents 4194f5c + afaebd6 commit 91acdec
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions src/jefferson/EnlightmentCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class EnlightmentCenter extends Robot {
int[] allyECIDs;
MapLocation[] allyECLocs; // absolute locations
int[] allyDistances;
int numSentHoriz;
int numSentVert;
int numSentDiag;

// Environment and enemy; maps from MapLocations to influences. If influence is unknown it is null.
Map<MapLocation, Integer> enemyECLocsToInfluence;
Expand Down Expand Up @@ -124,6 +127,11 @@ public EnlightmentCenter(RobotController rc) throws GameActionException {
initialFaf.writeLocation(myLocation.x & 127, myLocation.y & 127); // modulo 128
firstRoundIDsToConsider = new ArrayList<Integer>();

// Spawn direction variables
numSentHoriz = 0;
numSentVert = 0;
numSentDiag = 0;

// Initialize environment and enemy tracking variables
enemyECLocsToInfluence = new HashMap<MapLocation, Integer>();
neutralECLocsToInfluence = new HashMap<MapLocation, Integer>();
Expand Down Expand Up @@ -496,7 +504,7 @@ int getOptimalSlandererInfluence(int maxInfluence) {
}

MapLocation optimalSlandererDestination() {
MapLocation enemyLocation = isMidGame ? optimalDestinationMidGame(true) : optimalDestination(true);
MapLocation enemyLocation = isMidGame ? optimalDestinationMidGame(true) : optimalDestination(true, false, false, true);
Direction awayFromEnemy = enemyLocation.directionTo(myLocation);
MapLocation oneStep = myLocation.add(awayFromEnemy);
int dx = oneStep.x - myLocation.x;
Expand Down Expand Up @@ -1038,8 +1046,11 @@ MapLocation optimalDestination(boolean includeNeutral) {
MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanceOverEnemy) {
return optimalDestination(includeNeutral, prioritizeDistanceOverEnemy, false);
}
MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanceOverEnemy, boolean killerPolitician) {
return optimalDestination(includeNeutral, prioritizeDistanceOverEnemy, killerPolitician, false);
}

MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanceOverEnemy, boolean killerPolitician) {
MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanceOverEnemy, boolean killerPolitician, boolean sendingSlanderer) {
boolean randomFallback = false;
if (currentRound < searchBounds.length) {
int[] dArr = randomDestination();
Expand Down Expand Up @@ -1148,17 +1159,48 @@ MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanc
}
} else {
// Randomly launch vertically, horizontally, or at 45 degrees (45 deg TODO).
// System.out.println("randomly launching in all dirs");
System.out.println("----------------------------");
int[] dHoriz = optimalHorizontalDestination(horizAbsSum, horizSum, horizFurthestDirection, horizFurthestWall);
int[] dVert = optimalVerticalDestination(vertAbsSum, vertSum, vertFurthestDirection, vertFurthestWall);
double rand = Math.random();
if (rand < (double)horizFurthestWall/denom) {
dArr = dVert;
} else if (rand < (double)(horizFurthestWall + vertFurthestWall)/denom) {
dArr = dHoriz;
System.out.println("Horiz Furthest Wall/Denom " + horizFurthestWall/denom);
System.out.println("Vert Furthest Wall/Denom " + (double)(horizFurthestWall + vertFurthestWall)/denom);
if (numSentDiag == 0 && numSentHoriz == 0 && numSentVert == 0 || sendingSlanderer) {
if (rand < (double)horizFurthestWall/denom) {
dArr = dVert;
if (!sendingSlanderer) { numSentVert += 1; }
System.out.println("Sending vertically.");
} else if (rand < (double)(horizFurthestWall + vertFurthestWall)/denom) {
dArr = dHoriz;
if (!sendingSlanderer) { numSentHoriz += 1; }
System.out.println("Sending horizontally.");
} else {
dArr[0] = dHoriz[0];
dArr[1] = dVert[1];
if (!sendingSlanderer) { numSentDiag += 1; }
System.out.println("Sending diagonally.");
}
} else {
dArr[0] = dHoriz[0];
dArr[1] = dVert[1];
double horizRatio = ((double)(numSentHoriz)/(double)(numSentVert + numSentHoriz + numSentDiag))/((double)horizFurthestWall/denom);
double vertRatio = ((double)(numSentVert)/(double)(numSentVert + numSentHoriz + numSentDiag))/((double)vertFurthestWall/denom);
double diagRatio = ((double)(numSentDiag)/(double)(numSentVert + numSentHoriz + numSentDiag))/((double)(denom - horizFurthestWall - vertFurthestWall)/denom);
System.out.println("Horiz Proportion: " + horizRatio);
System.out.println("Vert Proportion: " + vertRatio);
System.out.println("Diag Proportion: " + diagRatio);
if (horizRatio <= vertRatio && horizRatio <= diagRatio) {
dArr = dHoriz;
System.out.println("Sending horizontally.");
numSentHoriz += 1;
} else if (vertRatio <= horizRatio && vertRatio <= diagRatio) {
dArr = dVert;
System.out.println("Sending vertically.");
numSentVert += 1;
} else {
dArr[0] = dHoriz[0];
dArr[1] = dVert[1];
System.out.println("Sending diagonally.");
numSentDiag += 1;
}
}
}
} else if (symmetries[0] == true) {
Expand Down Expand Up @@ -1223,6 +1265,7 @@ MapLocation optimalDestination(boolean includeNeutral, boolean prioritizeDistanc
dArr = randomDestination();
}
enemyLocation = myLocation.translate(dArr[0], dArr[1]);
System.out.println("Sending guy to: " + enemyLocation);
spawnDestIsGuess = true;
}
return enemyLocation;
Expand Down

0 comments on commit 91acdec

Please sign in to comment.