Exemplo n.º 1
0
  /**
   * Returns likelihood that region could defeat neighboring regions.
   *
   * @param region
   * @return
   */
  protected static Map<Region, Float> checkAttacks(Region region) {
    Map<Region, Float> result = new HashMap<Region, Float>();

    for (Neighbor neighbor : region.neighbors) {
      // check if region can be attacked
      if (RegionUtils.canAttack(region, neighbor)) {
        float[] battleDamage = BattleUtils.calculateBattleDamage(region, neighbor.region, 0);
        result.put(neighbor.region, battleDamage[0] - battleDamage[1]);
      }
    }

    return result;
  }
Exemplo n.º 2
0
  /**
   * Returns collection of attacks for given score factor, ordered by descending score.
   *
   * @param overworld
   * @param player
   * @param scoreThreshold
   * @param scoreFactor
   * @return
   */
  protected static Collection<Move> getAttacks(
      Overworld overworld, Player player, ScoreFactor scoreThreshold, ScoreFactor scoreFactor) {

    Map<Float, Move> attacks = new TreeMap<Float, Move>();

    // go through each region
    for (Region region : overworld.regions) {
      if (region.player.equals(player) && region.unit != null && region.unit.hasAttack) {

        // check each neighbor
        for (Neighbor neighbor : region.neighbors) {
          if (RegionUtils.canAttack(region, neighbor)) {

            ScoreFactor score = new ScoreFactor();
            float scoreValue = 0;
            boolean aboveThreshold = true;

            // get each score type
            for (ScoreFactor.Type type : ScoreFactor.Type.values()) {
              if (scoreThreshold.usesType(type) || scoreFactor.usesType(type)) {
                switch (type) {
                  case BATTLE_STRENGTH_CHANGE:
                    if (neighbor.type != Neighbor.Type.RANGED) {
                      score.addFactor(type, getBattleStrengthChange(region, neighbor, false));
                    } else {
                      score.addFactor(type, 0.5f);
                    }
                    break;
                  case BATTLE_LIKELIHOOD:
                    score.addFactor(
                        type, BattleUtils.calculateBattleLikelihood(region, neighbor.region));
                    break;
                  case ISLAND_PERCENTAGE:
                    score.addFactor(type, RegionUtils.getIslandPercentage(region.island, player));
                    break;
                  case ISLAND_STRENGTH:
                    score.addFactor(type, RegionUtils.getIslandStrength(region.island, player));
                    break;
                  case RANDOM:
                    score.addFactor(type, Utils.random().nextFloat());
                    break;
                  case ISLAND_STRENGTH_CHANGE:
                    // ignore
                    break;
                }

                // check if score meets threshold
                if (scoreThreshold.usesType(type)) {
                  aboveThreshold &= score.getScore(type) >= scoreThreshold.getScore(type);
                }

                // update score value
                if (scoreFactor.usesType(type)) {
                  scoreValue += score.getScore(type) * scoreFactor.getScore(type);
                }
              }
            }

            // score above threshold
            if (aboveThreshold) {
              attacks.put(scoreValue, new Move(Move.Type.ATTACK, region, neighbor.region));
              System.out.println(
                  String.format("\tpossible attack %f: %s", scoreValue, attacks.get(scoreValue)));
              System.out.println("\t\t" + score);
            }
          }
        }
      }
    }

    return attacks.values();
  }