Class UnitMover

  extended bycivquest.units.UnitMover
Direct Known Subclasses:

public abstract class UnitMover
extends java.lang.Object

A UnitMover is responsible for calculating moves of groups of units - all located on the same field - to a neighbor-field. It transforms an Action ("move to field X") into one or more GameChanges and applys all relevant rules while doing this. Usually, it will use a MoveCalculator for the low-level-calculation-jobs. The sense of a UnitMover is offering orders for moving units that can easily be executed and that are really up-to-date. You couldn't just use the data in a MovePath calculated last turn because since then, almost everything might have changed.

Constructor Summary
Method Summary
 GameChange[] getChangesForMoveAlongPath(PossibleMovePath path)
          Returns all GameChanges necessary for moving the unit one step along the given PossibleMovePath.
abstract  GameChange[] getUnitMoveChanges(java.util.Collection units, Field field)
          Returns all GameChanges necessary for moving the given unit-group to the given field.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public UnitMover()
Method Detail


public abstract GameChange[] getUnitMoveChanges(java.util.Collection units,
                                                Field field)
Returns all GameChanges necessary for moving the given unit-group to the given field. The move given by the GameChanges is only valid (in the sense of the rules) if they get executed immediately after they where returned.

units - a Collection of units, all located on the same Field, expected to be non-empty
field - a neighbor-field of the units current field
GameChanges necessary for performing the move - they must be executed in the order they are stored in the array. The array is empty, if the move can't be performed within this turn. null gets returned if the move isn't possible at all (the MoveCalculator returns an ImpossibleMovePath)


public GameChange[] getChangesForMoveAlongPath(PossibleMovePath path)
Returns all GameChanges necessary for moving the unit one step along the given PossibleMovePath. Three cases exist: 1. path contains no PathStep: Nothing has to be done, so an empty array will be returned 2. path contains exactly one PathStep: The Field stored in this PathStep will be used as dest-field 3. path contains >= two PathSteps: The Field stored in the second PathStep will be used as dest-field

In the cases (2.) and (3.), the returned array will be the same as if you had called getUnitMoveChanges(Collection, Field) directly with the field mentioned above as argument.

In case (1.), path remains unchanged. In case (2.), the (only) PathStep gets removed, if the units are located on the dest-field (without any distance-away-property set) afterwards. In case (3.), the first PathStep gets removed, if all units move until/beyond its Field. The second PathStep gets treated as the first one in case (2.) (see above), all subsequent PathSteps remain unchanged in this case. The path also remains unchanged, if getUnitMoveChanges(Collection, Field) returns null because it is not possible any longer (in fact, you can forget about it anyway in this case).

path - any PossibleMovePath
GameChange-array as defined above