Package net.sf.colossus.game
Class Legion
java.lang.Object
net.sf.colossus.game.Legion
- Direct Known Subclasses:
LegionClientSide
,LegionServerSide
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The creatures in this legion.private MasterHex
The current position of the legion on the masterboard.protected List
<Legion.AcquirableDecision> private EntrySide
The side this legion entered a battle in.private final String
The ID of the marker of this legion.private boolean
Flag if the legion has moved in the current masterboard round.static final Comparator
<Legion> A comparator to order legions by points, with Titan armies first.static final Comparator
<Legion> A comparator to order legions by points, with Titan armies first.private final Player
The player/game combination owning this Legion.private CreatureType
The creature recruited in last recruit phaseprivate boolean
Flag to remember a "skip (split|move|recruit) this time"private boolean
Flag if the legion has teleported in the current masterboard round.private boolean
Flag to remember that legion has been visited this phase -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
addCreature
(CreatureType type) (package private) List
<Legion.AcquirableDecision> calculateAcquirableDecisions
(int score, int points) From the given score, awarding given points, calculate the choices for each threshold that will be crossed.boolean
canFlee()
boolean
contains
(CreatureType type) final boolean
Two legions are considered equal if they have the same marker.findEligibleAngels
(int points) Calculate which angels this legion can get in its current land when crossing the given points thresholdTODO should be an unmodifiable List, but can't at the moment since both derived classes and users might still expect to change it TODO should be List, but subtypes are still covariant Retrieves a list of all creature types in this legion.Returns the current position of the legion.int
Returns the number of creatures in this legion.Retrieves the player this legion belongs to.abstract int
TODO unify between the two derived classes if possible -- the handling of Titans is quite different, although it should have the same resultboolean
getTitan()
boolean
final int
hashCode()
boolean
hasMoved()
boolean
boolean
boolean
boolean
hasTitan()
int
numCreature
(CreatureType creatureType) int
numLords()
int
abstract void
removeCreature
(CreatureType type) void
setCurrentHex
(MasterHex newPosition) Places the legion into the new position.void
setEntrySide
(EntrySide entrySide) void
setMoved
(boolean moved) void
setRecruit
(CreatureType recruit) void
setSkipThisTime
(boolean skipIt) void
setTeleported
(boolean teleported) void
setupAcquirableDecisions
(int score, int points) Calculate the acquirableDecisions and store them in the legion.void
setVisitedThisPhase
(boolean visited) final String
toString()
Returns the markerId for debug and serialisation purposes.
-
Field Details
-
ORDER_TITAN_THEN_POINTS
A comparator to order legions by points, with Titan armies first. This only works properly if all legions are owned by the same player. The case of two legions with titans is not handled. WARNING: This is not consistent with equals() since two legions with the same point value are considered equal. -
ORDER_TITAN_THEN_POINTS_THEN_MARKER
A comparator to order legions by points, with Titan armies first. If same points, by MarkerId. This only works properly if all legions are owned by the same player. The case of two legions with titans is not handled. -
player
The player/game combination owning this Legion. Never null. -
currentHex
The current position of the legion on the masterboard. Never null. -
creatures
The creatures in this legion. -
markerId
The ID of the marker of this legion. Used as identifier for serialization purposes. Never null. -
moved
private boolean movedFlag if the legion has moved in the current masterboard round. -
teleported
private boolean teleportedFlag if the legion has teleported in the current masterboard round. -
entrySide
The side this legion entered a battle in. -
decisions
-
angelsToAcquire
protected int angelsToAcquire -
recruit
The creature recruited in last recruit phase -
skipThisTime
private boolean skipThisTimeFlag to remember a "skip (split|move|recruit) this time" -
visitedThisPhase
private boolean visitedThisPhaseFlag to remember that legion has been visited this phase
-
-
Constructor Details
-
Legion
-
-
Method Details
-
getPlayer
Retrieves the player this legion belongs to.- Returns:
- The matching player. Never null.
-
setCurrentHex
Places the legion into the new position.- Parameters:
newPosition
- the hex that will be the new position. Not null.- See Also:
-
getCurrentHex
Returns the current position of the legion.- Returns:
- the hex the legion currently is on.
- See Also:
-
getCreatures
TODO should be an unmodifiable List, but can't at the moment since both derived classes and users might still expect to change it TODO should be List, but subtypes are still covariant -
getMarkerId
-
getLongMarkerId
-
hasTitan
public boolean hasTitan() -
getTitan
- Returns:
- returns the Titan Creature, if this legions has the titan, or null if it hasn't.
-
getHeight
public int getHeight()Returns the number of creatures in this legion.- Returns:
- the number of creatures in the legion
-
setMoved
public void setMoved(boolean moved) -
hasMoved
public boolean hasMoved() -
setTeleported
public void setTeleported(boolean teleported) -
hasTeleported
public boolean hasTeleported() -
setSkipThisTime
public void setSkipThisTime(boolean skipIt) -
getSkipThisTime
public boolean getSkipThisTime() -
setVisitedThisPhase
public void setVisitedThisPhase(boolean visited) -
getVisitedThisPhase
public boolean getVisitedThisPhase() -
contains
-
addCreature
-
removeCreature
-
setEntrySide
-
getEntrySide
-
getPointValue
public abstract int getPointValue()TODO unify between the two derived classes if possible -- the handling of Titans is quite different, although it should have the same result -
getRecruit
-
setRecruit
-
hasRecruited
public boolean hasRecruited() -
hasSummonable
public boolean hasSummonable() -
canFlee
public boolean canFlee() -
numCreature
-
numLords
public int numLords() -
numRangestrikers
public int numRangestrikers() -
setupAcquirableDecisions
public void setupAcquirableDecisions(int score, int points) Calculate the acquirableDecisions and store them in the legion.- Parameters:
score
-points
-
-
calculateAcquirableDecisions
From the given score, awarding given points, calculate the choices for each threshold that will be crossed. E.g. 375+150 => 525 will cross 400 and 500, so one has to make two decisions: 400: take angel (or not); 500: take angel, archangel (or nothing). This only calculates them, does not set them in the legion yet; so a client or AI could use this for theoretical calculations "how much / which angels would I get if..." without modifying the legions state itself. The limits for "which one can get" due to legion height, creatures left count and terrain are considered (implicitly, because findEligibleAngels(tmpScore) checks them).- Parameters:
score
- Current score of playerpoints
- Points to be added which entitle to acquiring- Returns:
- List of decisions
-
getCreatureTypes
Retrieves a list of all creature types in this legion. This matches getCreatures() but lists the types instead of the individual creatures.- Returns:
- A list of all creature types in this legion.
-
findEligibleAngels
Calculate which angels this legion can get in its current land when crossing the given points threshold- Parameters:
points
- Score threshold (100, ..., 400, 500) for which to get angel- Returns:
- list of creatures that can be get at that threshold
-
toString
Returns the markerId for debug and serialisation purposes. Since this is relevant for the network protocol, the method is declared final. -
hashCode
public final int hashCode() -
equals
Two legions are considered equal if they have the same marker. Even though contents may change over time, we consider two legions to be the same as long as they have the same marker. This notion of equality is used throughout the code, so we enforce it by having both {equals(Object)
andhashCode()
declared final.
-