Package net.sf.colossus.game
Class Legion
- java.lang.Object
-
- net.sf.colossus.game.Legion
-
- Direct Known Subclasses:
LegionClientSide
,LegionServerSide
public abstract class Legion extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Legion.AcquirableDecision
Data for one pending decision.
-
Field Summary
Fields Modifier and Type Field Description protected int
angelsToAcquire
private java.util.List<Creature>
creatures
The creatures in this legion.private MasterHex
currentHex
The current position of the legion on the masterboard.protected java.util.List<Legion.AcquirableDecision>
decisions
private EntrySide
entrySide
The side this legion entered a battle in.private java.lang.String
markerId
The ID of the marker of this legion.private boolean
moved
Flag if the legion has moved in the current masterboard round.static java.util.Comparator<Legion>
ORDER_TITAN_THEN_POINTS
A comparator to order legions by points, with Titan armies first.static java.util.Comparator<Legion>
ORDER_TITAN_THEN_POINTS_THEN_MARKER
A comparator to order legions by points, with Titan armies first.private Player
player
The player/game combination owning this Legion.private CreatureType
recruit
The creature recruited in last recruit phaseprivate boolean
skipThisTime
Flag to remember a "skip (split|move|recruit) this time"private boolean
teleported
Flag if the legion has teleported in the current masterboard round.private boolean
visitedThisPhase
Flag to remember that legion has been visited this phase
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addCreature(CreatureType type)
(package private) java.util.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)
boolean
equals(java.lang.Object obj)
Two legions are considered equal if they have the same marker.java.util.List<CreatureType>
findEligibleAngels(int points)
Calculate which angels this legion can get in its current land when crossing the given points thresholdjava.util.List<? extends Creature>
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 java.util.List<CreatureType>
getCreatureTypes()
Retrieves a list of all creature types in this legion.MasterHex
getCurrentHex()
Returns the current position of the legion.EntrySide
getEntrySide()
int
getHeight()
Returns the number of creatures in this legion.java.lang.String
getLongMarkerId()
java.lang.String
getMarkerId()
Player
getPlayer()
Retrieves the player this legion belongs to.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 resultCreatureType
getRecruit()
boolean
getSkipThisTime()
Creature
getTitan()
boolean
getVisitedThisPhase()
int
hashCode()
boolean
hasMoved()
boolean
hasRecruited()
boolean
hasSummonable()
boolean
hasTeleported()
boolean
hasTitan()
int
numCreature(CreatureType creatureType)
int
numLords()
int
numRangestrikers()
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)
java.lang.String
toString()
Returns the markerId for debug and serialisation purposes.
-
-
-
Field Detail
-
ORDER_TITAN_THEN_POINTS
public static final java.util.Comparator<Legion> 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
public static final java.util.Comparator<Legion> 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
private final Player player
The player/game combination owning this Legion. Never null.
-
currentHex
private MasterHex currentHex
The current position of the legion on the masterboard. Never null.
-
creatures
private final java.util.List<Creature> creatures
The creatures in this legion.
-
markerId
private final java.lang.String markerId
The ID of the marker of this legion. Used as identifier for serialization purposes. Never null.
-
moved
private boolean moved
Flag if the legion has moved in the current masterboard round.
-
teleported
private boolean teleported
Flag if the legion has teleported in the current masterboard round.
-
entrySide
private EntrySide entrySide
The side this legion entered a battle in.
-
decisions
protected java.util.List<Legion.AcquirableDecision> decisions
-
angelsToAcquire
protected int angelsToAcquire
-
recruit
private CreatureType recruit
The creature recruited in last recruit phase
-
skipThisTime
private boolean skipThisTime
Flag to remember a "skip (split|move|recruit) this time"
-
visitedThisPhase
private boolean visitedThisPhase
Flag to remember that legion has been visited this phase
-
-
Method Detail
-
getPlayer
public Player getPlayer()
Retrieves the player this legion belongs to.- Returns:
- The matching player. Never null.
-
setCurrentHex
public void setCurrentHex(MasterHex newPosition)
Places the legion into the new position.- Parameters:
newPosition
- the hex that will be the new position. Not null.- See Also:
getCurrentHex()
-
getCurrentHex
public MasterHex getCurrentHex()
Returns the current position of the legion.- Returns:
- the hex the legion currently is on.
- See Also:
setCurrentHex(MasterHex)
-
getCreatures
public java.util.List<? extends Creature> 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
public java.lang.String getMarkerId()
-
getLongMarkerId
public java.lang.String getLongMarkerId()
-
hasTitan
public boolean hasTitan()
-
getTitan
public Creature 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
public boolean contains(CreatureType type)
-
addCreature
public abstract void addCreature(CreatureType type)
-
removeCreature
public abstract void removeCreature(CreatureType type)
-
setEntrySide
public void setEntrySide(EntrySide entrySide)
-
getEntrySide
public EntrySide 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
public CreatureType getRecruit()
-
setRecruit
public void setRecruit(CreatureType recruit)
-
hasRecruited
public boolean hasRecruited()
-
hasSummonable
public boolean hasSummonable()
-
canFlee
public boolean canFlee()
-
numCreature
public int numCreature(CreatureType creatureType)
-
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
java.util.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. 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
public java.util.List<CreatureType> 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
public java.util.List<CreatureType> findEligibleAngels(int points)
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
public final java.lang.String toString()
Returns the markerId for debug and serialisation purposes. Since this is relevant for the network protocol, the method is declared final.- Overrides:
toString
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
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.- Overrides:
equals
in classjava.lang.Object
-
-