From afaebd621272a56c7ffeb0a4d4569f838a0204f8 Mon Sep 17 00:00:00 2001 From: nikhilsardana <2018nsardana@tjhsst.edu> Date: Thu, 28 Jan 2021 17:53:02 -0500 Subject: [PATCH] derandomize initial spawn --- src/jefferson/EnlightmentCenter.java | 61 ++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/src/jefferson/EnlightmentCenter.java b/src/jefferson/EnlightmentCenter.java index 39a0ec2..5ef5d30 100644 --- a/src/jefferson/EnlightmentCenter.java +++ b/src/jefferson/EnlightmentCenter.java @@ -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 enemyECLocsToInfluence; @@ -124,6 +127,11 @@ public EnlightmentCenter(RobotController rc) throws GameActionException { initialFaf.writeLocation(myLocation.x & 127, myLocation.y & 127); // modulo 128 firstRoundIDsToConsider = new ArrayList(); + // Spawn direction variables + numSentHoriz = 0; + numSentVert = 0; + numSentDiag = 0; + // Initialize environment and enemy tracking variables enemyECLocsToInfluence = new HashMap(); neutralECLocsToInfluence = new HashMap(); @@ -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; @@ -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(); @@ -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) { @@ -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;