games.strategy.engine.data
Class GameMap

java.lang.Object
  extended by games.strategy.engine.data.GameDataComponent
      extended by games.strategy.engine.data.GameMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Territory>

public class GameMap
extends GameDataComponent
implements java.lang.Iterable<Territory>

Version:
1.0 Holds a collection of territories, and the links between them. Utility methods for finding routes and distances between different territories.
Author:
Sean Bridges
See Also:
Serialized Form

Field Summary
static Match<Territory> IS_LAND
           
static Match<Territory> IS_LAND_OR_WATER
           
static Match<Territory> IS_WATER
           
 
Method Summary
protected  void addConnection(Territory t1, Territory t2)
           
protected  void addTerritory(Territory t1)
           
 int getDistance(Territory t1, Territory t2)
          Returns the distance between two territories.
 int getDistance(Territory t1, Territory t2, Match<Territory> cond)
          Returns the distance between two territories.
 int getLandDistance(Territory t1, Territory t2)
          Returns the distance between two territories on Land.
 Route getLandRoute(Territory t1, Territory t2)
          Returns the shortest route between two territories.
 java.util.Set<Territory> getNeighbors(Territory t)
          Returns a territories neighbors.
 java.util.Set<Territory> getNeighbors(Territory territory, int distance)
          Returns all territories within distance from territory, excluding the territory itself.
 java.util.Set<Territory> getNeighbors(Territory t, Match<Territory> cond)
          Returns a territories neighbors.
 Route getRoute(Territory t1, Territory t2)
          Returns the shortest route between two territories.
 Route getRoute(Territory t1, Territory t2, Match<Territory> cond)
          Returns the shortest route between two territories.
 java.util.Collection<Territory> getTerritories()
           
 java.util.Collection<Territory> getTerritoriesOwnedBy(PlayerID player)
           
 Territory getTerritory(java.lang.String s)
          Return the territory with the given name, or null if no territory can be found.
 Territory getTerritoryFromCoordinates(int... coordinate)
           
 int getWaterDistance(Territory t1, Territory t2)
          Returns the distance between two territories on Water.
 Route getWaterRoute(Territory t1, Territory t2)
          Returns the shortest route between two territories.
 int getXDimension()
           
 int getYDimension()
           
 boolean isCoordinateValid(int... coordinate)
           
 boolean isValidRoute(Route route)
          Tests that each territory is connected to the preceding territory
 java.util.Iterator<Territory> iterator()
           
 void setGridDimensions(int... gridDimensions)
           
 
Methods inherited from class games.strategy.engine.data.GameDataComponent
getData, readInternal, writeInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_WATER

public static final Match<Territory> IS_WATER

IS_LAND

public static final Match<Territory> IS_LAND

IS_LAND_OR_WATER

public static final Match<Territory> IS_LAND_OR_WATER
Method Detail

setGridDimensions

public void setGridDimensions(int... gridDimensions)

getXDimension

public int getXDimension()

getYDimension

public int getYDimension()

getTerritoryFromCoordinates

public Territory getTerritoryFromCoordinates(int... coordinate)

isCoordinateValid

public boolean isCoordinateValid(int... coordinate)

addTerritory

protected void addTerritory(Territory t1)

addConnection

protected void addConnection(Territory t1,
                             Territory t2)

getTerritory

public Territory getTerritory(java.lang.String s)
Return the territory with the given name, or null if no territory can be found. Case sensitive.


getNeighbors

public java.util.Set<Territory> getNeighbors(Territory t)
Returns a territories neighbors.


getNeighbors

public java.util.Set<Territory> getNeighbors(Territory t,
                                             Match<Territory> cond)
Returns a territories neighbors.


getNeighbors

public java.util.Set<Territory> getNeighbors(Territory territory,
                                             int distance)
Returns all territories within distance from territory, excluding the territory itself.


getRoute

public Route getRoute(Territory t1,
                      Territory t2)
Returns the shortest route between two territories. Returns null if no route exists.


getLandRoute

public Route getLandRoute(Territory t1,
                          Territory t2)
Returns the shortest route between two territories. Returns null if no route exists.


getWaterRoute

public Route getWaterRoute(Territory t1,
                           Territory t2)
Returns the shortest route between two territories. Returns null if no route exists.


getRoute

public Route getRoute(Territory t1,
                      Territory t2,
                      Match<Territory> cond)
Returns the shortest route between two territories. That satisfies the given test. Returns null if no route exists.


getDistance

public int getDistance(Territory t1,
                       Territory t2)
Returns the distance between two territories. Returns -1 if they are not connected.


getLandDistance

public int getLandDistance(Territory t1,
                           Territory t2)
Returns the distance between two territories on Land. Returns -1 if they are not connected.


getWaterDistance

public int getWaterDistance(Territory t1,
                            Territory t2)
Returns the distance between two territories on Water. Returns -1 if they are not connected.


getDistance

public int getDistance(Territory t1,
                       Territory t2,
                       Match<Territory> cond)
Returns the distance between two territories. Returns -1 if no connection can be found. TerritoryTest is an arbitrary condition that must be satisfied by all territories in the path.


getTerritories

public java.util.Collection<Territory> getTerritories()

iterator

public java.util.Iterator<Territory> iterator()
Specified by:
iterator in interface java.lang.Iterable<Territory>

getTerritoriesOwnedBy

public java.util.Collection<Territory> getTerritoriesOwnedBy(PlayerID player)

isValidRoute

public boolean isValidRoute(Route route)
Tests that each territory is connected to the preceding territory