コード例 #1
0
ファイル: AI.java プロジェクト: slauson/Tactics
  /**
   * Returns change in battle strength if unit at region switches places with neighbor.
   *
   * @param region
   * @param neighbor
   * @param includeNeighborStrengthChange true if change in neighbor strength should be included
   * @return
   */
  private static float getBattleStrengthChange(
      Region region, Neighbor neighbor, boolean includeNeighborStrengthChange) {
    // get current strengths of region, neighbor
    float regionStrength = RegionUtils.getRegionBattleStrength(region);
    float neighborStrength = RegionUtils.getRegionBattleStrength(neighbor.region);

    // swap units, see change in strengths
    Unit tempUnit = region.unit;
    region.unit = neighbor.region.unit;
    neighbor.region.unit = tempUnit;

    Player tempPlayer = region.player;
    region.player = neighbor.region.player;
    neighbor.region.player = tempPlayer;

    float regionMoveStrength = RegionUtils.getRegionBattleStrength(region);
    float neighborMoveStrength = RegionUtils.getRegionBattleStrength(neighbor.region);

    // put units back
    tempUnit = region.unit;
    region.unit = neighbor.region.unit;
    neighbor.region.unit = tempUnit;

    tempPlayer = region.player;
    region.player = neighbor.region.player;
    neighbor.region.player = tempPlayer;

    if (includeNeighborStrengthChange) {
      return (regionMoveStrength + neighborMoveStrength - regionStrength - neighborStrength + 2)
          / 4;
    } else {
      return (regionMoveStrength - regionStrength + 1) / 2;
    }
  }
コード例 #2
0
ファイル: AI.java プロジェクト: slauson/Tactics
  /**
   * Returns changes in region strengths for each possible move.
   *
   * @param region
   * @return
   */
  protected static Map<Neighbor, Float> checkMoves(Region region) {
    Map<Neighbor, Float> result = new HashMap<Neighbor, Float>();

    for (Neighbor neighbor : region.neighbors) {
      // check if neighbor can be moved to
      if (RegionUtils.canMove(region, neighbor)) {
        // get current strengths of region, neighbor
        float regionStrength = RegionUtils.getRegionBattleStrength(region);
        float neighborStrength = RegionUtils.getRegionBattleStrength(neighbor.region);

        // swap units, see change in strengths
        Unit tempUnit = region.unit;
        region.unit = neighbor.region.unit;
        neighbor.region.unit = tempUnit;

        Player tempPlayer = region.player;
        region.player = neighbor.region.player;
        neighbor.region.player = tempPlayer;

        float regionMoveStrength = RegionUtils.getRegionBattleStrength(region);
        float neighborMoveStrength = RegionUtils.getRegionBattleStrength(neighbor.region);

        // put units back
        tempUnit = region.unit;
        region.unit = neighbor.region.unit;
        neighbor.region.unit = tempUnit;

        tempPlayer = region.player;
        region.player = neighbor.region.player;
        neighbor.region.player = tempPlayer;

        result.put(
            neighbor,
            regionMoveStrength + neighborMoveStrength - regionStrength - neighborStrength);
      }
    }

    return result;
  }