private int findBestCorner() { double[][] pasture = rc.senseCowGrowth(); double max = 0; int corner = 0; double total = 0; // top left corner for (int k = 0; k < 10; k++) { for (int a = 0; a < 10; a++) { total += pasture[k][a]; } } if (total > max) { max = total; corner = 1; } total = 0; // top right corner for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) { for (int a = 0; a < 10; a++) { total += pasture[k][a]; } } if (total > max) { max = total; corner = 2; } total = 0; // bottom left corner for (int k = 0; k < 10; k++) { for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) { total += pasture[k][a]; } } if (total > max) { max = total; corner = 3; } total = 0; // bottom right corner for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) { for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) { total += pasture[k][a]; } } if (total > max) { max = total; corner = 4; } return corner; }
public static MapLocation[] BestPastureSpots(RobotController rc) { MapLocation[] empty = new MapLocation[1]; try { // Check if a robot is spawnable and spawn one if it is double growthRates[][] = rc.senseCowGrowth(); int countofBestSpots = 0; double best = 0.0001; for (int i = 0; i < rc.getMapWidth(); i++) { for (int k = 0; k < rc.getMapHeight(); k++) { if (growthRates[i][k] > best) { best = growthRates[i][k]; countofBestSpots = 1; } else if (growthRates[i][k] == best) { countofBestSpots++; } SpawnSoldiers(rc); } } MapLocation[] bestSpots = new MapLocation[countofBestSpots]; int index = 0; for (int i = 0; i < rc.getMapWidth(); i++) { for (int k = 0; k < rc.getMapHeight(); k++) { if (growthRates[i][k] == best) { bestSpots[index] = new MapLocation(i, k); index++; } SpawnSoldiers(rc); } } for (int i = 1; i < countofBestSpots; i++) { for (int j = i; j < countofBestSpots; j++) { int dist1 = rc.getLocation().distanceSquaredTo(bestSpots[j]); int dist2 = rc.getLocation().distanceSquaredTo(bestSpots[j]); if (dist1 < dist2) { MapLocation temp = bestSpots[j]; bestSpots[j] = bestSpots[j - 1]; bestSpots[j - 1] = temp; } SpawnSoldiers(rc); } } return bestSpots; } catch (Exception e) { e.printStackTrace(); System.out.println("Utility Exception"); } return empty; }
public static void createTerrainMap() { // Get cow density field and map dimensions double cowDensMap[][] = hq.senseCowGrowth(); int mapY = cowDensMap.length, mapX = cowDensMap[0].length; // Initialize terrain map array terrainMap = new int[mapY][mapX]; // Scan over map to identify types of terrain at each location for (int i = 0; i < mapY; i++) { for (int j = 0; j < mapX; j++) { TerrainTile t = hq.senseTerrainTile(new MapLocation(j, i)); if (t == TerrainTile.valueOf("NORMAL")) terrainMap[i][j] = NORMAL; else if (t == TerrainTile.valueOf("ROAD")) terrainMap[i][j] = ROAD; else if (t == TerrainTile.valueOf("VOID")) terrainMap[i][j] = WALL; else terrainMap[i][j] = OFFMAP; } } }
public static void initializeGameVars(RobotController rc) throws GameActionException { hq = rc; team = hq.getTeam(); enemy = team.opponent(); cowDensMap = hq.senseCowGrowth(); mapY = cowDensMap.length; mapX = cowDensMap[0].length; idealNumPastures = computeNumPastures(); enemyHQ = rc.senseEnemyHQLocation(); teamHQ = rc.senseHQLocation(); createTerrainMap(); desiredPASTRs = findPastureLocs(); // System.out.println("Desired pastures : " + Arrays.deepToString(desiredPASTRs)); initializerRun = true; rush = startRush(rc); rand = new Random(17); }
// finds best corner to collect milk where the return is an int as follows: // 1 2 // 3 4 public static int findBestCorner(RobotController rc) { double[][] pasture = rc.senseCowGrowth(); double[] voids = new double[4]; double[] cows = new double[4]; double[] distances = new double[4]; double max = 0; int corner = 0; double total = 0; MapLocation target = null; MapLocation current = rc.senseHQLocation(); for (int k = 1; k <= 4; k++) { switch (k) { case 1: target = new MapLocation(5, 5); break; case 2: target = new MapLocation(rc.getMapWidth() - 6, 5); break; case 3: target = new MapLocation(5, rc.getMapHeight() - 6); break; default: target = new MapLocation(rc.getMapWidth() - 6, rc.getMapHeight() - 6); break; } while (target.x != current.x || target.y != current.y) { if (rc.senseTerrainTile(current) == TerrainTile.VOID) { total++; } current = current.add(current.directionTo(target)); } voids[k - 1] = total; distances[k - 1] = rc.senseHQLocation().distanceSquaredTo(target); total = 0; current = rc.senseHQLocation(); } // top left corner for (int k = 0; k < 10; k++) { for (int a = 0; a < 10; a++) { total += pasture[k][a]; } } cows[0] = total; total = 0; // top right corner for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) { for (int a = 0; a < 10; a++) { total += pasture[k][a]; } } cows[1] = total; total = 0; // bottom left corner for (int k = 0; k < 10; k++) { for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) { total += pasture[k][a]; } } cows[2] = total; total = 0; // bottom right corner for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) { for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) { total += pasture[k][a]; } } cows[3] = total; for (int k = 0; k < 4; k++) { total = cows[k] * 1 - voids[k] * 50 - distances[k] * .001; if (total > max) { max = total; corner = k + 1; } } return corner; }