dip.world
Class Position

java.lang.Object
  extended bydip.world.Position
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Position
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Stores all the mutable (state) information for a given TurnState. Immutable data is retained in the Power/Province/etc. objects; only mutable data is stored here.

This object can be cloned, and should be cloned, when creating a new Position based upon previous Position data. Several clone methods are available, each optimized for speed and cloning requirements.

WARNING: this code is not MT (Multithread) safe!

This class is heavily optimized, as adjudicator performance is highly dependent upon the performance of this class.

The clone() methods are not strictly implemented; they call a constructor to assist in cloning rather than call super.clone(). This is done for performance reasons.

See Also:
Serialized Form

Field Summary
protected  Map map
           
protected  java.util.Map powerMap
           
protected  dip.world.Position.ProvinceData[] provArray
           
 
Constructor Summary
Position(Map map)
           
 
Method Summary
 java.lang.Object clone()
          Deep clone of the contents of this Position.
 Position cloneExceptDislodged()
          Deep clone of everything except dislodged units.
 Position cloneExceptUnits()
          Deep clone of everything *except* dislodged & non-dislodged units; (e.g., SC ownership, Power Info, etc.)
 Unit getDislodgedUnit(Province province)
          Get the dislodged unit in this Province.
 int getDislodgedUnitCount()
          Returns the number of provinces with dislodged units
 Province[] getDislodgedUnitProvinces()
          Returns an array of provinces with dislodged units
 Province[] getDislodgedUnitProvinces(Power power)
          Gets all the Provinces with dislodged Units for a particular power.
 Province[] getHomeSupplyCenters()
          Returns an array of provinces with home supply centers
 Province[] getHomeSupplyCenters(Power power)
          Returns an Array of the Home Supply Centers for a given power (whether or not they are owned by that power)
 Power getLastOccupier(Province province)
          Returns the Power that last occupied a given space.
 Province[] getOwnedSupplyCenters()
          Returns an array of provinces with owned supply centers
 Province[] getOwnedSupplyCenters(Power power)
          Returns an Array of the owned Supply Centers for a given Power (whether or not they are home supply centers)
 Province[] getProvinces()
          Convenience method: Returns an array of Provinces
 Power getSupplyCenterHomePower(Province province)
          Get the home power of the supply center; null if no supply center or home power
 Power getSupplyCenterOwner(Province province)
          Get the owner of the supply center; null if no owner or no supply center.
 Unit getUnit(Province province)
          Get the unit contained in this Province.
 int getUnitCount()
          Returns the number of provinces with non-dislodged units
 Province[] getUnitProvinces()
          Returns an array of provinces with non-dislodged units
 Province[] getUnitProvinces(Power power)
          Gets all the Provinces with non-dislodged Units for a particular power.
 boolean hasAnOwnedHomeSC(Power power)
          Determines if a Power has at least one owned Home Supply Center.
 boolean hasDislodgedUnit(Province province)
          Determines if there is a dislodged unit present in this province.
 boolean hasDislodgedUnit(Province province, Unit.Type unitType)
          Test if the given type of unit is contained in this Province.
 boolean hasSupplyCenterOwner(Province province)
          Determine if this Province contains a supply center
 boolean hasUnit(Province province)
          Determines if there is a unit present in this province.
 boolean hasUnit(Province province, Unit.Type unitType)
          Test if the given type of unit is contained in this Province.
 boolean isEliminated(Power power)
          Returns true if this Power has been eliminated.
 boolean isSupplyCenterAHome(Province province)
          Determine if this Province contains a Home supply center
 void setDislodgedUnit(Province province, Unit unit)
          Set the dislodged unit contained in this province; null to eliminate an existing unit.
 void setEliminated(Power power, boolean value)
          Set whether this Power has been eliminated.
 void setEliminationStatus(Power[] powers)
          Scans the Position; sets/unsets elimination depending upon if a given Power has any units (including dislodged units) or supply centers on the map
 void setLastOccupier(Province province, Power power)
          Sets the Power that last occupied a given space.
 void setSupplyCenterHomePower(Province province, Power power)
          Set the owner of a home supply center.
 void setSupplyCenterOwner(Province province, Power power)
          Set the owner of the supply center.
 void setUnit(Province province, Unit unit)
          Set the unit contained in this province; null to eliminate an existing unit.
 int size()
          The Number of Provinces in this Position
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

powerMap

protected final java.util.Map powerMap

provArray

protected final dip.world.Position.ProvinceData[] provArray

map

protected final Map map
Constructor Detail

Position

public Position(Map map)
Method Detail

size

public final int size()
The Number of Provinces in this Position


getProvinces

public final Province[] getProvinces()
Convenience method: Returns an array of Provinces


isEliminated

public boolean isEliminated(Power power)
Returns true if this Power has been eliminated. False by default.


setEliminated

public void setEliminated(Power power,
                          boolean value)
Set whether this Power has been eliminated.


setEliminationStatus

public void setEliminationStatus(Power[] powers)
Scans the Position; sets/unsets elimination depending upon if a given Power has any units (including dislodged units) or supply centers on the map


setSupplyCenterOwner

public void setSupplyCenterOwner(Province province,
                                 Power power)
Set the owner of the supply center.


setSupplyCenterHomePower

public void setSupplyCenterHomePower(Province province,
                                     Power power)
Set the owner of a home supply center.


hasSupplyCenterOwner

public boolean hasSupplyCenterOwner(Province province)
Determine if this Province contains a supply center


isSupplyCenterAHome

public boolean isSupplyCenterAHome(Province province)
Determine if this Province contains a Home supply center


getSupplyCenterHomePower

public Power getSupplyCenterHomePower(Province province)
Get the home power of the supply center; null if no supply center or home power


getSupplyCenterOwner

public Power getSupplyCenterOwner(Province province)
Get the owner of the supply center; null if no owner or no supply center.


setUnit

public void setUnit(Province province,
                    Unit unit)
Set the unit contained in this province; null to eliminate an existing unit.


hasUnit

public boolean hasUnit(Province province)
Determines if there is a unit present in this province.


getUnit

public Unit getUnit(Province province)
Get the unit contained in this Province. Returns null if no unit exists.


hasUnit

public boolean hasUnit(Province province,
                       Unit.Type unitType)
Test if the given type of unit is contained in this Province.


hasDislodgedUnit

public boolean hasDislodgedUnit(Province province,
                                Unit.Type unitType)
Test if the given type of unit is contained in this Province.


setDislodgedUnit

public void setDislodgedUnit(Province province,
                             Unit unit)
Set the dislodged unit contained in this province; null to eliminate an existing unit.


getDislodgedUnit

public Unit getDislodgedUnit(Province province)
Get the dislodged unit in this Province. Returns null if no dislodged unit exists.


setLastOccupier

public void setLastOccupier(Province province,
                            Power power)
Sets the Power that last occupied a given space. Note that this is not intended to be used for Supply Center ownership (which only changes in the Fall season); use setSupplyCenterOwner() instead.


getLastOccupier

public Power getLastOccupier(Province province)
Returns the Power that last occupied a given space. Note that this is not intended to be used for Supply Center ownership (which only changes in the Fall season); use getSupplyCenterOwner() instead.


hasDislodgedUnit

public boolean hasDislodgedUnit(Province province)
Determines if there is a dislodged unit present in this province.


getUnitProvinces

public Province[] getUnitProvinces()
Returns an array of provinces with non-dislodged units


getDislodgedUnitProvinces

public Province[] getDislodgedUnitProvinces()
Returns an array of provinces with dislodged units


getUnitCount

public int getUnitCount()
Returns the number of provinces with non-dislodged units


getDislodgedUnitCount

public int getDislodgedUnitCount()
Returns the number of provinces with dislodged units


getHomeSupplyCenters

public Province[] getHomeSupplyCenters()
Returns an array of provinces with home supply centers


getHomeSupplyCenters

public Province[] getHomeSupplyCenters(Power power)
Returns an Array of the Home Supply Centers for a given power (whether or not they are owned by that power)


hasAnOwnedHomeSC

public boolean hasAnOwnedHomeSC(Power power)
Determines if a Power has at least one owned Home Supply Center.

An owned home supply center need not have a unit present.


getOwnedSupplyCenters

public Province[] getOwnedSupplyCenters(Power power)
Returns an Array of the owned Supply Centers for a given Power (whether or not they are home supply centers)


getOwnedSupplyCenters

public Province[] getOwnedSupplyCenters()
Returns an array of provinces with owned supply centers


clone

public java.lang.Object clone()
Deep clone of the contents of this Position.


cloneExceptUnits

public Position cloneExceptUnits()
Deep clone of everything *except* dislodged & non-dislodged units; (e.g., SC ownership, Power Info, etc.)


cloneExceptDislodged

public Position cloneExceptDislodged()
Deep clone of everything except dislodged units.


getUnitProvinces

public Province[] getUnitProvinces(Power power)
Gets all the Provinces with non-dislodged Units for a particular power.


getDislodgedUnitProvinces

public Province[] getDislodgedUnitProvinces(Power power)
Gets all the Provinces with dislodged Units for a particular power.



Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.