public void igniteBuildingsCloseToHQ(int numBuildings, int maxDistance) { // ignite warehouses closest to their HQ List<Building> closeBuildings = enemyHeadquarters.getBuildingsWithinDistance(maxDistance); Queue<Building> closeEnemies = new ArrayDeque<>(); for (Building b : closeBuildings) { if (b.owner != player) { closeEnemies.add(b); } } Set<Warehouse> bribeableWarehouses = warehouseUtilities.getBribeableWarehouses(); // ignite int numTurns = numBuildings; while (numTurns > 0) { if (!closeEnemies.isEmpty()) { Building buildingToFire = closeEnemies.poll(); // get the closest warehouse to this building that is still usable Warehouse whToAttackWIth = warehouseUtilities.getClosestWarehouse(buildingToFire, bribeableWarehouses); if (whToAttackWIth != null && player.bribesRemaining > 0) { whToAttackWIth.ignite(buildingToFire); bribeableWarehouses.remove(whToAttackWIth); } } numTurns--; } }
public void joeFiddle() { EnemyHeadquartersUtilities enemyHeadquartersUtilities = new EnemyHeadquartersUtilities(enemyHeadquarters, game); Building enemyEhqNeighbor = null; Map<Building, WeatherStationUtilities.CardinalDirection> enemyHqNeighbor = enemyHeadquartersUtilities.getEnemyHeadquartersNeighbors(); for (Map.Entry<Building, WeatherStationUtilities.CardinalDirection> enemyneighbor : enemyHqNeighbor.entrySet()) { if (enemyneighbor != null && enemyneighbor.getKey().health > 0) { enemyEhqNeighbor = enemyneighbor.getKey(); break; } } if (enemyEhqNeighbor != null) { List<Warehouse> myAttackers = player.warehouses; while (player.bribesRemaining > 0) { Warehouse myAttacker = warehouseUtilities.getClosestWarehouse(enemyEhqNeighbor, myAttackers); if (myAttacker != null) { myAttacker.ignite(enemyEhqNeighbor); myAttackers.remove(myAttacker); } } } }
public void igniteTargetsUsingClosestWarehouses( List<Building> targets, List<Warehouse> myWarehouses, int bribesToSpend) { Map<Warehouse, Building> targetsForWarehouses = warehouseUtilities.getTargetsForWarehouses(targets, myWarehouses, bribesToSpend); for (Map.Entry<Warehouse, Building> entry : targetsForWarehouses.entrySet()) { entry.getKey().ignite(entry.getValue()); } }
/** * This is called every time the AI is asked to respond with a command during their turn * * @return represents if you want to end your turn. true means end the turn, false means to keep * your turn going and re-call runTurn() */ public boolean runTurn() { // // <<-- Creer-Merge: runTurn -->> - Code you add between this comment and the end // comment will be preserved between Creer re-runs. myAttackers = warehouseUtilities.getHealthyAndUnbribed(player.warehouses); enemyAttackers = warehouseUtilities.getHealthyAndUnbribed(player.otherPlayer.warehouses); // joeFiddle(); // jeffWeather2(); // jeffWeather(); georgeFiddle(); // if (player.bribesRemaining > 0) { System.out.println("BRIBES REMAINING"); } return true; // <<-- /Creer-Merge: runTurn -->> }
public Boolean attackUsingNearestWarehouse(Building target) { Warehouse myAttacker = warehouseUtilities.getClosestWarehouse(target, myAttackers); if (myAttacker != null) { player.log(myAttacker.id + " : " + target.id); myAttacker.ignite(target); myAttackers.remove(myAttacker); return true; } return false; }
public Building focusedBurnStrategy() { // return enemyHeadquarters; // Kill warehouses before ANYTHING ELSE // List<Warehouse> killableWarehouses = // policeDepartmentUtilities.canKill(player.otherPlayer.warehouses); // while(killableWarehouses.size() > 0 && // policeDepartmentUtilities.getFirstBribeablePoliceStation() != null && player.bribesRemaining // > 0) { // // policeDepartmentUtilities.getFirstBribeablePoliceStation().raid(killableWarehouses.get(0)); // killableWarehouses.remove(0); // } // If we go on turn two, we want to NOT blow in the same direction the other dude is blowing // We'd ALSO like to ignite the fire he's (probably) going to fan in our face // Logic for choosing a different direction.....First load all friendly buildings on fire. Map<Building, WeatherStationUtilities.CardinalDirection> friendlyNeighbors = friendlyHeadquartersUtilities.getFriendlyHeadquartersNeighbors(); List<Building> surroundingBuildingsOnFire = new ArrayList<>(); for (Map.Entry<Building, WeatherStationUtilities.CardinalDirection> friendlyHeadquartersNeightbor : friendlyNeighbors.entrySet()) { if (friendlyHeadquartersNeightbor.getKey().fire > 0 || friendlyHeadquartersNeightbor.getKey().isHeadquarters) { surroundingBuildingsOnFire.add(friendlyHeadquartersNeightbor.getKey()); } } // Remove them from the list of options. If all buildings are on fire, just choose one of // theirs at random. if (surroundingBuildingsOnFire.size() < friendlyNeighbors.size()) { for (Building neighbor : surroundingBuildingsOnFire) { friendlyNeighbors.remove(neighbor); } } else { // Use the building on their side with the least fire on our side if (friendlyNeighbors.get(myHeadquarters) != null) { friendlyNeighbors.remove(myHeadquarters); } Collections.sort( surroundingBuildingsOnFire, new Comparator<Building>() { @Override public int compare(Building o1, Building o2) { if (o1.fire > o2.fire) { return 1; } else if (o1.fire < o2.fire) { return -1; } return 0; } }); while (friendlyNeighbors.size() >= 2) { // Leave 1 around. The one with fewest fire. friendlyNeighbors.remove(surroundingBuildingsOnFire.get(0)); surroundingBuildingsOnFire.remove(0); } } Map.Entry<Building, WeatherStationUtilities.CardinalDirection> firelessDirection = friendlyNeighbors.entrySet().iterator().next(); Pair<Building, WeatherStationUtilities.CardinalDirection> cardinalBuilding; if (firelessDirection.getValue().name().equals("south")) { cardinalBuilding = new Pair<>( enemyHeadquarters.buildingSouth, WeatherStationUtilities.CardinalDirection.south); } else if (firelessDirection.getValue().name().equals("north")) { cardinalBuilding = new Pair<>( enemyHeadquarters.buildingNorth, WeatherStationUtilities.CardinalDirection.north); } else if (firelessDirection.getValue().name().equals("west")) { cardinalBuilding = new Pair<>( enemyHeadquarters.buildingEast, WeatherStationUtilities.CardinalDirection.east); } else { cardinalBuilding = new Pair<>( enemyHeadquarters.buildingWest, WeatherStationUtilities.CardinalDirection.west); } // Map<Building, WeatherStationUtilities.CardinalDirection> buildings = // enemyHeadquartersUtilities.getEnemyHeadquartersNeighbors(); String nextDirection = weatherStationUtilities.getNextWeather().direction; // // //Do NOT light our own HQ on fire! // if(buildings.get(myHeadquarters) != null) { // buildings.remove(myHeadquarters); // } // String correctDirection = weatherStationUtilities.getOppositeOf(cardinalBuilding.getValue()); boolean directionNeedsChanging = !(cardinalBuilding.getValue().name().equals(correctDirection)); // for (Map.Entry<Building, WeatherStationUtilities.CardinalDirection> currentBuilding : // buildings.entrySet()) { // if (weatherStationUtilities.isWeatherOpposite(cardinalBuilding.getValue().name(), // nextDirection)) { // directionNeedsChanging = false; // cardinalBuilding = currentBuilding; // break; // } // } // IF HQ IS CLOSE ENOUGH, USE IT INSTEAD LOGIC // END HQ IS CLOSE ENOUGH LOGIC // Get a list of all our warehouses. Use them to burn buildings around the enemy HQ Set<Warehouse> bribeableWarehouses = warehouseUtilities.getBribeableWarehouses(); while (cardinalBuilding.getKey().fire < 11 && player.bribesRemaining > 0) { Warehouse attacker = warehouseUtilities.getClosestWarehouse(cardinalBuilding.getKey(), bribeableWarehouses); if (attacker != null) { attacker.ignite(cardinalBuilding.getKey()); bribeableWarehouses.remove(attacker); } else { break; } } // Change direction first. Make sure we fan flames correctly while (player.bribesRemaining > 0 && directionNeedsChanging && weatherStationUtilities.getNextBribeableWeatherStation() != null) { WeatherStationUtilities.WeatherDirection direction = weatherStationUtilities.getDirection( weatherStationUtilities.getNextWeather().direction, weatherStationUtilities.getOppositeOf(cardinalBuilding.getValue())); if (direction.equals(WeatherStationUtilities.WeatherDirection.Backward)) { System.out.println( "WeatherStation opposite value: " + weatherStationUtilities.getOppositeOf(cardinalBuilding.getValue())); System.out.println("Next Direction: " + weatherStationUtilities.getNextWeather().direction); System.out.println("Rotating clockwise"); weatherStationUtilities.getNextBribeableWeatherStation().rotate(); } else if (direction.equals(WeatherStationUtilities.WeatherDirection.Clockwise)) { System.out.println( "WeatherStation opposite value: " + weatherStationUtilities.getOppositeOf(cardinalBuilding.getValue())); System.out.println("Next Direction: " + weatherStationUtilities.getNextWeather().direction); System.out.println("Rotating clockwise."); weatherStationUtilities.getNextBribeableWeatherStation().rotate(); directionNeedsChanging = false; } else if (direction.equals(WeatherStationUtilities.WeatherDirection.CounterClockwise)) { System.out.println( "WeatherStation opposite value: " + weatherStationUtilities.getOppositeOf(cardinalBuilding.getValue())); System.out.println("Next Direction: " + weatherStationUtilities.getNextWeather().direction); System.out.println("Rotating counterclockwise"); weatherStationUtilities.getNextBribeableWeatherStation().rotate(true); directionNeedsChanging = false; } else { break; } } // Intensify as much as possible while (player.bribesRemaining > 0 && weatherStationUtilities.getNextWeather().intensity < 10 && weatherStationUtilities.getNextBribeableWeatherStation() != null) { weatherStationUtilities.getNextBribeableWeatherStation().intensify(); } // First priority: Raid the enemy HQ if it would be useful to dish out extra pain if (player.bribesRemaining > 0 && policeDepartmentUtilities.atLeastOnePoliceStationStanding() && enemyHeadquarters.exposure > 0) { policeDepartmentUtilities.getFirstBribeablePoliceStation().raid(enemyHeadquarters); } // Increase other fires around enemy HQ // Last priority: Play defensive and see if we can fire department away some of burn that's // hurting us. if (player.bribesRemaining > 0) { System.out.println("Calling the firefighters!"); fireExtinguishAroundHQ(player.bribesRemaining); } return cardinalBuilding.getKey(); // Check if fire would hurt our HQ and use it the Fire Department to put out fires }