Beispiel #1
0
  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--;
    }
  }
Beispiel #2
0
  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);
        }
      }
    }
  }
Beispiel #3
0
 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;
 }
Beispiel #4
0
  /**
   * Tries to extinguish flames in the direction opposite of the next forecast(first) Then goes for
   * the largest buildings (next)
   *
   * @param bribesToUse
   * @return number of turns used
   */
  public int fireExtinguishAroundHQ(int bribesToUse) {
    // first get HQ
    Warehouse ourHQ = player.headquarters;
    int bribesLeft = Math.min(bribesToUse, player.bribesRemaining);
    int bribesUsed = 0;

    if (bribesLeft <= 0) {
      return 0;
    }

    Stack<FireDepartment> fireDepartments = new Stack<>();

    for (FireDepartment fdpt : player.fireDepartments) {
      if (fdpt != null && fdpt.bribed == false && fdpt.health > 0) {
        fireDepartments.push(fdpt);
      }
    }

    // get the wind direction
    WeatherStationUtilities.CardinalDirection dir =
        Enum.valueOf(WeatherStationUtilities.CardinalDirection.class, game.nextForecast.direction);
    dir = dir.rotate180();

    // get the building in the opposite direction
    Building adjacentUpwindBuilding = ourHQ.getAdjacentBuilding(dir);
    if (adjacentUpwindBuilding != null && adjacentUpwindBuilding.owner == player) {
      int numberOfExtinguishes = adjacentUpwindBuilding.fire / 2;

      int numberOfTurnsToUse = Math.min(bribesLeft, numberOfExtinguishes);
      numberOfTurnsToUse = Math.min(numberOfTurnsToUse, fireDepartments.size());

      for (int bribes = 0; bribes < numberOfTurnsToUse; bribes++) {
        if (fireDepartments.isEmpty() || bribesLeft <= 0) {
          return bribesUsed;
        }
        FireDepartment dpt = fireDepartments.pop();
        dpt.extinguish(adjacentUpwindBuilding);
        bribesUsed++;
        bribesLeft--;
      }
    }

    // now evenly use the other 3 buildings
    List<Building> adjacentUrgentBuildings = new ArrayList<>();
    List<Building> closeBuildings = ourHQ.getBuildingsWithinDistance(1);
    for (Building b : closeBuildings) {
      if (b != null && b.owner == player && b.fire > 1) {
        adjacentUrgentBuildings.add(b);
      }
    }

    if (bribesLeft <= 0 || adjacentUrgentBuildings.isEmpty()) {
      return bribesUsed;
    }

    while (bribesLeft >= 0) {
      // find the highest fire building
      Building highestFire = adjacentUrgentBuildings.get(0);

      for (Building b : adjacentUrgentBuildings) {
        if (b.fire > highestFire.fire) {
          highestFire = b;
        }
      }

      if (highestFire.fire <= 1 || fireDepartments.empty()) {
        return bribesUsed;
      }

      // put out the highest fire
      FireDepartment fdpt = fireDepartments.pop();
      fdpt.extinguish(highestFire);
      bribesLeft--;
      bribesUsed++;
    }

    return bribesUsed;
  }
Beispiel #5
0
  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
  }