games.strategy.triplea.delegate
Class BattleCalculator

java.lang.Object
  extended by games.strategy.triplea.delegate.BattleCalculator

public class BattleCalculator
extends java.lang.Object

Version:
1.0 Utiltity class for determing casualties and selecting casualties. The code was being dduplicated all over the place.
Author:
Sean Bridges

Method Summary
static Tuple<java.util.List<Unit>,java.util.List<Unit>> categorizeLowLuckAirUnits(java.util.Collection<Unit> units, Territory location)
          http://triplea.sourceforge.net/mywiki/Forum#nabble-td4658925%7Ca4658925 returns two lists, the first list is the air units that can be evenly divided into groups of 3 or 6 (depending on radar) the second list is all the air units that do not fit in the first list
static java.util.Collection<Unit> getAACasualties(java.util.Collection<Unit> planes, DiceRoll dice, IDelegateBridge bridge, PlayerID defender, PlayerID attacker, GameData data, GUID battleID, Territory terr)
          Choose plane casualties according to specified rules
static int getAAHits(java.util.Collection<Unit> units, IDelegateBridge bridge, int[] dice)
           
static IntegerMap<UnitType> getCosts(PlayerID player, GameData data)
          Return map where keys are unit types and values are PU costs of that unit type
static java.util.Map<Unit,java.util.Collection<Unit>> getDependents(java.util.Collection<Unit> targets, GameData data)
           
static int getRolls(java.util.Collection<Unit> units, PlayerID id, boolean defend)
           
static int getRolls(java.util.Collection<Unit> units, PlayerID id, boolean defend, int availableSupport)
           
static int getRolls(Unit unit, PlayerID id, boolean defend)
           
static int getRolls(Unit unit, PlayerID id, boolean defend, int artillerySupport)
           
static int getTUV(java.util.Collection<Unit> units, IntegerMap<UnitType> costs)
          Return the total unit value
static int getTUV(java.util.Collection<Unit> units, PlayerID player, IntegerMap<UnitType> costs, GameData data)
          Return the total unit value for a certain player and his allies
static java.util.Collection<Unit> IndividuallyFiredAACasualties(java.util.Collection<Unit> planes, DiceRoll dice, IDelegateBridge bridge, PlayerID player)
          Choose plane casualties based on individual AA shots at each aircraft.
static java.util.Collection<Unit> RandomAACasualties(java.util.Collection<Unit> planes, DiceRoll dice, IDelegateBridge bridge)
          Choose plane casualties randomly
static CasualtyDetails selectCasualties(PlayerID player, java.util.Collection<Unit> targets, IDelegateBridge bridge, java.lang.String text, GameData data, DiceRoll dice, boolean defending, GUID battleID)
           
static CasualtyDetails selectCasualties(java.lang.String step, PlayerID player, java.util.Collection<Unit> targets, IDelegateBridge bridge, java.lang.String text, GameData data, DiceRoll dice, boolean defending, GUID battleID, boolean headLess, int extraHits)
           
static void sortPreBattle(java.util.List<Unit> units, GameData data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sortPreBattle

public static void sortPreBattle(java.util.List<Unit> units,
                                 GameData data)

getAAHits

public static int getAAHits(java.util.Collection<Unit> units,
                            IDelegateBridge bridge,
                            int[] dice)

getAACasualties

public static java.util.Collection<Unit> getAACasualties(java.util.Collection<Unit> planes,
                                                         DiceRoll dice,
                                                         IDelegateBridge bridge,
                                                         PlayerID defender,
                                                         PlayerID attacker,
                                                         GameData data,
                                                         GUID battleID,
                                                         Territory terr)
Choose plane casualties according to specified rules


categorizeLowLuckAirUnits

public static Tuple<java.util.List<Unit>,java.util.List<Unit>> categorizeLowLuckAirUnits(java.util.Collection<Unit> units,
                                                                                         Territory location)
http://triplea.sourceforge.net/mywiki/Forum#nabble-td4658925%7Ca4658925 returns two lists, the first list is the air units that can be evenly divided into groups of 3 or 6 (depending on radar) the second list is all the air units that do not fit in the first list


RandomAACasualties

public static java.util.Collection<Unit> RandomAACasualties(java.util.Collection<Unit> planes,
                                                            DiceRoll dice,
                                                            IDelegateBridge bridge)
Choose plane casualties randomly


IndividuallyFiredAACasualties

public static java.util.Collection<Unit> IndividuallyFiredAACasualties(java.util.Collection<Unit> planes,
                                                                       DiceRoll dice,
                                                                       IDelegateBridge bridge,
                                                                       PlayerID player)
Choose plane casualties based on individual AA shots at each aircraft.


selectCasualties

public static CasualtyDetails selectCasualties(PlayerID player,
                                               java.util.Collection<Unit> targets,
                                               IDelegateBridge bridge,
                                               java.lang.String text,
                                               GameData data,
                                               DiceRoll dice,
                                               boolean defending,
                                               GUID battleID)

selectCasualties

public static CasualtyDetails selectCasualties(java.lang.String step,
                                               PlayerID player,
                                               java.util.Collection<Unit> targets,
                                               IDelegateBridge bridge,
                                               java.lang.String text,
                                               GameData data,
                                               DiceRoll dice,
                                               boolean defending,
                                               GUID battleID,
                                               boolean headLess,
                                               int extraHits)
Parameters:
battleID - may be null if we are not in a battle (eg, if this is an aa fire due to moving

getDependents

public static java.util.Map<Unit,java.util.Collection<Unit>> getDependents(java.util.Collection<Unit> targets,
                                                                           GameData data)

getCosts

public static IntegerMap<UnitType> getCosts(PlayerID player,
                                            GameData data)
Return map where keys are unit types and values are PU costs of that unit type

Parameters:
player - The player to get costs schedule for
data - The game data.
Returns:
a map of unit types to PU cost

getTUV

public static int getTUV(java.util.Collection<Unit> units,
                         IntegerMap<UnitType> costs)
Return the total unit value

Parameters:
units - A collection of units
costs - An integer map of unit types to costs.
Returns:
the total unit value.

getTUV

public static int getTUV(java.util.Collection<Unit> units,
                         PlayerID player,
                         IntegerMap<UnitType> costs,
                         GameData data)
Return the total unit value for a certain player and his allies

Parameters:
units - A collection of units
player - The player to calculate the TUV for.
costs - An integer map of unit types to costs
Returns:
the total unit value.

getRolls

public static int getRolls(java.util.Collection<Unit> units,
                           PlayerID id,
                           boolean defend)

getRolls

public static int getRolls(java.util.Collection<Unit> units,
                           PlayerID id,
                           boolean defend,
                           int availableSupport)

getRolls

public static int getRolls(Unit unit,
                           PlayerID id,
                           boolean defend)

getRolls

public static int getRolls(Unit unit,
                           PlayerID id,
                           boolean defend,
                           int artillerySupport)