2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
* You should have received a copy of the GNU General Public License
11
* along with this program; if not, write to the Free Software
12
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
package games.strategy.triplea.Dynamix_AI.Others;
17
import games.strategy.engine.data.GameData;
18
import games.strategy.engine.data.PlayerID;
19
import games.strategy.engine.data.Territory;
20
import games.strategy.engine.data.Unit;
21
import games.strategy.triplea.Dynamix_AI.DSettings;
22
import games.strategy.triplea.Dynamix_AI.DUtils;
23
import games.strategy.triplea.delegate.Matches;
24
import java.util.List;
30
public class Battle_RetreatTerCalculator
32
public static Territory CalculateBestRetreatTer(GameData data, PlayerID player, List<Territory> possibles, Territory battleTer)
34
List<Territory> ourCaps = DUtils.GetAllOurCaps_ThatWeOwn(data, player);
36
Territory highestScoringTer = null;
37
float highestScore = Integer.MIN_VALUE;
38
for(Territory ter : possibles)
42
float oldSurvivalChance = DUtils.GetSurvivalChanceOfArmy(data, player, ter, DUtils.GetTerUnitsAtEndOfTurn(data, player, ter), 500);
44
List<Unit> afterDefenders = DUtils.GetTerUnitsAtEndOfTurn(data, player, ter);
45
afterDefenders.removeAll(battleTer.getUnits().getMatches(Matches.unitIsOwnedBy(player)));
46
afterDefenders.addAll(battleTer.getUnits().getMatches(Matches.unitIsOwnedBy(player)));
48
float newSurvivalChance = DUtils.GetSurvivalChanceOfArmy(data, player, ter, afterDefenders, 500);
50
if(newSurvivalChance > .9F) //If this retreat ter is really safe
51
newSurvivalChance = .9F; //Then accept similar chances as equal
53
boolean isImportant = ourCaps.contains(ter);
54
float importantTerChanceRequired = DUtils.ToFloat(DSettings.LoadSettings().TR_reinforceStabalize_enemyAttackSurvivalChanceRequired);
55
//If this ter is important, and retreating here will make the ter safe, boost score a lot
56
if(isImportant && oldSurvivalChance < importantTerChanceRequired && newSurvivalChance >= importantTerChanceRequired)
59
score += newSurvivalChance * 10000;
60
score += DUtils.GetValueOfLandTer(ter, data, player);
62
if(score > highestScore)
65
highestScoringTer = ter;
68
return highestScoringTer;