games.strategy.triplea.delegate
Class MoveValidator

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

public class MoveValidator
extends java.lang.Object

Author:
Sean Bridges Provides some static methods for validating movement.

Field Summary
static java.lang.String CANNOT_LOAD_AND_UNLOAD_AN_ALLIED_TRANSPORT_IN_THE_SAME_ROUND
           
static java.lang.String CANNOT_VIOLATE_NEUTRALITY
           
static java.lang.String CANT_MOVE_THROUGH_IMPASSIBLE
           
static java.lang.String NOT_ALL_AIR_UNITS_CAN_LAND
           
static java.lang.String TOO_POOR_TO_VIOLATE_NEUTRALITY
           
static java.lang.String TRANSPORT_CANNOT_LOAD_AND_UNLOAD_AFTER_COMBAT
           
static java.lang.String TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_IN_A_PREVIOUS_PHASE
           
static java.lang.String TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_TO
           
 
Method Summary
static boolean canLand(java.util.Collection<Unit> airUnits, Territory territory, PlayerID player, GameData data)
          Returns true if the given air units can land in the given territory.
static int carrierCapacity(java.util.Collection<Unit> units)
           
static int carrierCost(java.util.Collection<Unit> units)
           
static java.util.Map<Unit,java.util.Collection<Unit>> carrierMustMoveWith(java.util.Collection<Unit> units, java.util.Collection<Unit> startUnits, GameData data, PlayerID player)
           
static boolean enemyDestroyerOnPath(Route route, PlayerID player, GameData data)
           
static Route getBestRoute(Territory start, Territory end, GameData data, PlayerID player, java.util.Collection<Unit> units)
          Get the route ignoring forced territories
static java.util.Collection<Unit> getFriendly(Territory territory, PlayerID player, GameData data)
           
static int getLeastMovement(java.util.Collection<Unit> units)
           
static int getMaxMovement(java.util.Collection<Unit> units)
           
static MustMoveWithDetails getMustMoveWith(Territory start, java.util.Collection<Unit> units, GameData data, PlayerID player)
           
static java.util.Collection<Unit> getNonLand(java.util.Collection<Unit> units)
           
static int getTransportCapacityFree(Territory territory, PlayerID id, GameData data, TransportTracker tracker)
           
static int getTransportCost(java.util.Collection<Unit> units)
           
static java.util.Collection<Unit> getUnitsThatCantGoOnWater(java.util.Collection<Unit> units)
           
static boolean hasConqueredNonBlitzedOnRoute(Route route, GameData data)
           
static boolean hasEnoughMovement(java.util.Collection<Unit> units, int length)
           
static boolean hasEnoughMovement(java.util.Collection<Unit> units, Route route)
          Tests the given collection of units to see if they have the movement necessary to move.
static boolean hasEnoughMovement(Unit unit, int length)
           
static boolean hasEnoughMovement(Unit unit, Route route)
          Tests the given unit to see if it has the movement necessary to move.
static boolean hasLand(Route route)
           
static boolean hasNeutralBeforeEnd(Route route)
           
static boolean hasSomeLand(java.util.Collection<Unit> units)
           
static boolean hasUnitsThatCantGoOnWater(java.util.Collection<Unit> units)
           
static boolean hasWater(Route route)
           
static boolean isBlitzable(Territory current, GameData data, PlayerID player)
           
static boolean isFriendly(PlayerID p1, PlayerID p2, GameData data)
           
static boolean isLoad(Route route)
           
static boolean isUnload(Route route)
           
static boolean onlyAlliedUnitsOnPath(Route route, PlayerID player, GameData data)
          Checks that there are no enemy units on the route except possibly at the end.
static boolean onlyIgnoredUnitsOnPath(Route route, PlayerID player, GameData data, boolean ignoreRouteEnd)
          Checks that there only transports, subs and/or allies on the route except at the end.
static boolean ownedByFriendly(Unit unit, PlayerID player, GameData data)
           
static java.lang.String validateCanal(Route route, PlayerID player, GameData data)
           
static MoveValidationResult validateMove(java.util.Collection<Unit> units, Route route, PlayerID player, java.util.Collection<Unit> transportsToLoad, boolean isNonCombat, java.util.List<UndoableMove> undoableMoves, GameData data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_IN_A_PREVIOUS_PHASE

public static final java.lang.String TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_IN_A_PREVIOUS_PHASE
See Also:
Constant Field Values

TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_TO

public static final java.lang.String TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_TO
See Also:
Constant Field Values

CANNOT_LOAD_AND_UNLOAD_AN_ALLIED_TRANSPORT_IN_THE_SAME_ROUND

public static final java.lang.String CANNOT_LOAD_AND_UNLOAD_AN_ALLIED_TRANSPORT_IN_THE_SAME_ROUND
See Also:
Constant Field Values

CANT_MOVE_THROUGH_IMPASSIBLE

public static final java.lang.String CANT_MOVE_THROUGH_IMPASSIBLE
See Also:
Constant Field Values

TOO_POOR_TO_VIOLATE_NEUTRALITY

public static final java.lang.String TOO_POOR_TO_VIOLATE_NEUTRALITY
See Also:
Constant Field Values

CANNOT_VIOLATE_NEUTRALITY

public static final java.lang.String CANNOT_VIOLATE_NEUTRALITY
See Also:
Constant Field Values

NOT_ALL_AIR_UNITS_CAN_LAND

public static final java.lang.String NOT_ALL_AIR_UNITS_CAN_LAND
See Also:
Constant Field Values

TRANSPORT_CANNOT_LOAD_AND_UNLOAD_AFTER_COMBAT

public static final java.lang.String TRANSPORT_CANNOT_LOAD_AND_UNLOAD_AFTER_COMBAT
See Also:
Constant Field Values
Method Detail

hasEnoughMovement

public static boolean hasEnoughMovement(java.util.Collection<Unit> units,
                                        Route route)
Tests the given collection of units to see if they have the movement necessary to move.


hasEnoughMovement

public static boolean hasEnoughMovement(java.util.Collection<Unit> units,
                                        int length)

hasEnoughMovement

public static boolean hasEnoughMovement(Unit unit,
                                        Route route)
Tests the given unit to see if it has the movement necessary to move.


hasEnoughMovement

public static boolean hasEnoughMovement(Unit unit,
                                        int length)

onlyAlliedUnitsOnPath

public static boolean onlyAlliedUnitsOnPath(Route route,
                                            PlayerID player,
                                            GameData data)
Checks that there are no enemy units on the route except possibly at the end. Submerged enemy units are not considered as they don't affect movement. AA and factory dont count as enemy.


onlyIgnoredUnitsOnPath

public static boolean onlyIgnoredUnitsOnPath(Route route,
                                             PlayerID player,
                                             GameData data,
                                             boolean ignoreRouteEnd)
Checks that there only transports, subs and/or allies on the route except at the end. AA and factory dont count as enemy.


enemyDestroyerOnPath

public static boolean enemyDestroyerOnPath(Route route,
                                           PlayerID player,
                                           GameData data)

hasConqueredNonBlitzedOnRoute

public static boolean hasConqueredNonBlitzedOnRoute(Route route,
                                                    GameData data)

isBlitzable

public static boolean isBlitzable(Territory current,
                                  GameData data,
                                  PlayerID player)

isUnload

public static boolean isUnload(Route route)

isLoad

public static boolean isLoad(Route route)

hasNeutralBeforeEnd

public static boolean hasNeutralBeforeEnd(Route route)

getTransportCost

public static int getTransportCost(java.util.Collection<Unit> units)

getUnitsThatCantGoOnWater

public static java.util.Collection<Unit> getUnitsThatCantGoOnWater(java.util.Collection<Unit> units)

hasUnitsThatCantGoOnWater

public static boolean hasUnitsThatCantGoOnWater(java.util.Collection<Unit> units)

carrierCapacity

public static int carrierCapacity(java.util.Collection<Unit> units)

carrierCost

public static int carrierCost(java.util.Collection<Unit> units)

hasWater

public static boolean hasWater(Route route)

hasLand

public static boolean hasLand(Route route)

canLand

public static boolean canLand(java.util.Collection<Unit> airUnits,
                              Territory territory,
                              PlayerID player,
                              GameData data)
Returns true if the given air units can land in the given territory. Does not take into account whether a battle has been fought in the territory already. Note units must only be air units


getNonLand

public static java.util.Collection<Unit> getNonLand(java.util.Collection<Unit> units)

getFriendly

public static java.util.Collection<Unit> getFriendly(Territory territory,
                                                     PlayerID player,
                                                     GameData data)

isFriendly

public static boolean isFriendly(PlayerID p1,
                                 PlayerID p2,
                                 GameData data)

ownedByFriendly

public static boolean ownedByFriendly(Unit unit,
                                      PlayerID player,
                                      GameData data)

getMaxMovement

public static int getMaxMovement(java.util.Collection<Unit> units)

getLeastMovement

public static int getLeastMovement(java.util.Collection<Unit> units)

getTransportCapacityFree

public static int getTransportCapacityFree(Territory territory,
                                           PlayerID id,
                                           GameData data,
                                           TransportTracker tracker)

hasSomeLand

public static boolean hasSomeLand(java.util.Collection<Unit> units)

validateMove

public static MoveValidationResult validateMove(java.util.Collection<Unit> units,
                                                Route route,
                                                PlayerID player,
                                                java.util.Collection<Unit> transportsToLoad,
                                                boolean isNonCombat,
                                                java.util.List<UndoableMove> undoableMoves,
                                                GameData data)

validateCanal

public static java.lang.String validateCanal(Route route,
                                             PlayerID player,
                                             GameData data)

getMustMoveWith

public static MustMoveWithDetails getMustMoveWith(Territory start,
                                                  java.util.Collection<Unit> units,
                                                  GameData data,
                                                  PlayerID player)

carrierMustMoveWith

public static java.util.Map<Unit,java.util.Collection<Unit>> carrierMustMoveWith(java.util.Collection<Unit> units,
                                                                                 java.util.Collection<Unit> startUnits,
                                                                                 GameData data,
                                                                                 PlayerID player)

getBestRoute

public static Route getBestRoute(Territory start,
                                 Territory end,
                                 GameData data,
                                 PlayerID player,
                                 java.util.Collection<Unit> units)
Get the route ignoring forced territories