~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/triplea/Dynamix_AI/Others/Battle_RetreatTerCalculator.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
13
 */
 
14
 
 
15
package games.strategy.triplea.Dynamix_AI.Others;
 
16
 
 
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;
 
25
 
 
26
/**
 
27
 *
 
28
 * @author Stephen
 
29
 */
 
30
public class Battle_RetreatTerCalculator
 
31
{
 
32
    public static Territory CalculateBestRetreatTer(GameData data, PlayerID player, List<Territory> possibles, Territory battleTer)
 
33
    {
 
34
        List<Territory> ourCaps = DUtils.GetAllOurCaps_ThatWeOwn(data, player);
 
35
 
 
36
        Territory highestScoringTer = null;
 
37
        float highestScore = Integer.MIN_VALUE;
 
38
        for(Territory ter : possibles)
 
39
        {
 
40
            float score = 0;
 
41
 
 
42
            float oldSurvivalChance = DUtils.GetSurvivalChanceOfArmy(data, player, ter, DUtils.GetTerUnitsAtEndOfTurn(data, player, ter), 500);
 
43
 
 
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)));
 
47
 
 
48
            float newSurvivalChance = DUtils.GetSurvivalChanceOfArmy(data, player, ter, afterDefenders, 500);
 
49
 
 
50
            if(newSurvivalChance > .9F) //If this retreat ter is really safe
 
51
                newSurvivalChance = .9F; //Then accept similar chances as equal
 
52
 
 
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)
 
57
                score += 100000;
 
58
 
 
59
            score += newSurvivalChance * 10000;
 
60
            score += DUtils.GetValueOfLandTer(ter, data, player);
 
61
 
 
62
            if(score > highestScore)
 
63
            {
 
64
                highestScore = score;
 
65
                highestScoringTer = ter;
 
66
            }
 
67
        }
 
68
        return highestScoringTer;
 
69
    }
 
70
}