civquest.units
Class MoveCalculator

java.lang.Object
  extended bycivquest.units.MoveCalculator
Direct Known Subclasses:
DijkstraMoveCalculator

public abstract class MoveCalculator
extends java.lang.Object

A MoveCalculator determines rules for moving units. It offers functions for calculating MovePaths and for actually moving units.


Constructor Summary
MoveCalculator()
           
 
Method Summary
 MovePath[] calculateMovePaths(java.util.Collection unitCollections, Field to)
          Calculates MovePaths for all unit-groups in the given Collection.
abstract  MovePath calculateOneMovePath(java.util.Collection unitCollection, Field to)
          Calculates a MovePath for a move of the given unit-group from its current position to Field .
static java.util.List constructUnitGroups(java.util.List units)
          Constructs unit-groups for the given units (see calculateMovePaths(java.util.Collection, civquest.Field)).
abstract  boolean moveUnit(long id, Coordinate to)
          Moves the unit with given id to field .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveCalculator

public MoveCalculator()
Method Detail

moveUnit

public abstract boolean moveUnit(long id,
                                 Coordinate to)
Moves the unit with given id to field . A unit with the given id must exist, as well as a field with coordinate . must to be a neighbor-field of the unit's current field. Implementations may decide to test for some of this "forbidden" cases. If any of these tests fails, the return-value is false, otherwise true. This function performs all necessary datastructure-updates.

Parameters:
id - unit-id as described
to - field we move to
Returns:
if everything was ok

calculateMovePaths

public MovePath[] calculateMovePaths(java.util.Collection unitCollections,
                                     Field to)
Calculates MovePaths for all unit-groups in the given Collection. A unit-group is number of units stored in a Collection that all have to be located on the SAME Field. If they aren't, this method will return nonsense. Start of a MovePath is the current position of a unit-group, destination the given Field to. The speed of a unit-group is always the speed of the slowest unit in the group.

Parameters:
to - the Field we want to move to
Returns:
an array with movepaths for all unit-groups in the given List

calculateOneMovePath

public abstract MovePath calculateOneMovePath(java.util.Collection unitCollection,
                                              Field to)
Calculates a MovePath for a move of the given unit-group from its current position to Field .

Parameters:
to - a Field
Returns:
a MovePath as described

constructUnitGroups

public static java.util.List constructUnitGroups(java.util.List units)
Constructs unit-groups for the given units (see calculateMovePaths(java.util.Collection, civquest.Field)). All units located at the same Field will be in the same group.

Parameters:
units - a List of units
Returns:
a List of unit-groups as described