Package net.sf.colossus.game
Class RecruitGraph
java.lang.Object
net.sf.colossus.game.RecruitGraph
Implementation of a graph dedicated to the Recruit "Tree" (it's a directed
graph, not a tree, as we can have cycle in theory).
Moved into game package. Does it belong more to game or variant package?
TODO this is still string-based, see comment in
TerrainRecruitLoader
- Author:
- Romain Dolbeau
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
The edge of the Recruit Graphstatic final class
Models a recruit option for a given creature.private static class
The vertex of the Recruit Graph -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<RecruitGraph.RecruitEdge>
private final List<RecruitGraph.RecruitVertex>
static final int
99 creatures can muster one means: can not muster at allprivate Caretaker
private final Map<String,
RecruitGraph.RecruitVertex> private static final Logger
private final IVariantKnower
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEdge
(String src, String dst, int number, MasterBoardTerrain terrain) Add an edge is the graph from a Creature to another, in a given number, in a given terrain.private RecruitGraph.RecruitEdge
addEdge
(RecruitGraph.RecruitVertex src, RecruitGraph.RecruitVertex dst, int number, MasterBoardTerrain terrain) private RecruitGraph.RecruitVertex
void
clear()
Clear the graph of all Vertex & Edge.getAllTerrainsWhereThisNumberOfCreatureRecruit
(String cre, int number) Return all the terrains (as String in a List) where the given number of creature of the given name can recruit.A list of what can recruit a creature.A list of what a creature can recruit.getBestPossibleRecruitEver
(String cre, Legion legion) Return the name of the best possible creature that is reachable trough the given creature from the given LegionInfo (can be null).(package private) Caretaker
private List<RecruitGraph.RecruitEdge>
getIncomingEdges
(String cre) Give the List of RecruitEdge where the given creature is the destination.int
What is the maximum "useful" number of a given creature for recruitment purpose (excluding "Any" or "AnyNonLord").private List<RecruitGraph.RecruitEdge>
getOutgoingEdges
(String cre) Give the List of RecruitEdge where the given creature is the source.getRecruitFromRecruiterTerrainNumber
(CreatureType cre, MasterBoardTerrain t, int number) Return the name of the recruit for the given number of the given recruiter in the given terrain, or null if there's none.private Variant
private RecruitGraph.RecruitVertex
boolean
isRecruitDistanceLessThan
(String lesser, String greater, int distance) Determine if a creature given by 'lesser' could potentially summon the higher valued creature given by 'greater' within N steps.int
numberOfRecruiterNeeded
(String recruiter, String recruit, MasterBoardTerrain terrain, MasterHex hex) void
setCaretaker
(Caretaker caretaker) Set the Caretaker to use for availability of creatures.private List<RecruitGraph.RecruitVertex>
Give the List of RecruitVertex still reachable through the given creature from the given Legion.private List<RecruitGraph.RecruitVertex>
traverse
(RecruitGraph.RecruitVertex s, Set<RecruitGraph.RecruitVertex> visited, Legion legion) Traverse the graph (depth first), assuming that all vertex in visited have been already visited, and using the given legion for availability of creatures (along with the caretakerInfo).
-
Field Details
-
LOGGER
-
caretaker
-
variantKnower
-
allVertex
-
allEdge
-
creatureToVertex
-
BIGNUM
public static final int BIGNUM99 creatures can muster one means: can not muster at all- See Also:
-
-
Constructor Details
-
RecruitGraph
-
-
Method Details
-
addVertex
-
getVertex
-
addEdge
private RecruitGraph.RecruitEdge addEdge(RecruitGraph.RecruitVertex src, RecruitGraph.RecruitVertex dst, int number, MasterBoardTerrain terrain) -
traverse
private List<RecruitGraph.RecruitVertex> traverse(RecruitGraph.RecruitVertex s, Set<RecruitGraph.RecruitVertex> visited, Legion legion) Traverse the graph (depth first), assuming that all vertex in visited have been already visited, and using the given legion for availability of creatures (along with the caretakerInfo). This will ignore any strange stuff such as Anything, AnyNonLord, and so on. OTOH It will not ignore the Titan.- Parameters:
s
- The base vertexvisited
- Already visited vertexeslegion
- The legion to use for availability- Returns:
- The list of all reachable Vertex from parameter s.
-
getCaretaker
Caretaker getCaretaker() -
getVariant
-
getOutgoingEdges
Give the List of RecruitEdge where the given creature is the source.- Parameters:
cre
- Name of the recruiting creature- Returns:
- A List of all the outgoing RecruitEdge.
-
getIncomingEdges
Give the List of RecruitEdge where the given creature is the destination.- Parameters:
cre
- Name of the recruited creature- Returns:
- A List of all the incoming RecruitEdge.
-
traverse
Give the List of RecruitVertex still reachable through the given creature from the given Legion.- Parameters:
cre
- Name of the base creature- Returns:
- A List of all the reachable RecruitVertex.
-
addEdge
Add an edge is the graph from a Creature to another, in a given number, in a given terrain.- Parameters:
src
- Name of the recruiting creaturedst
- Name of the recruited creaturenumber
- Number of recruitersterrain
- Terrain where the recruiting occurs
-
numberOfRecruiterNeeded
public int numberOfRecruiterNeeded(String recruiter, String recruit, MasterBoardTerrain terrain, MasterHex hex) -
setCaretaker
Set the Caretaker to use for availability of creatures.- Parameters:
caretaker
- The caretaker to use subsequently.
-
clear
public void clear()Clear the graph of all Vertex & Edge. -
getMaximumUsefulNumber
What is the maximum "useful" number of a given creature for recruitment purpose (excluding "Any" or "AnyNonLord"). return value of -1 or 0 means the Creature cannot recruit except itself.- Parameters:
cre
- Name of the creature considered.- Returns:
- The higher number of creatures needed to recruit something.
-
getAllTerrainsWhereThisNumberOfCreatureRecruit
public List<MasterBoardTerrain> getAllTerrainsWhereThisNumberOfCreatureRecruit(String cre, int number) Return all the terrains (as String in a List) where the given number of creature of the given name can recruit.- Parameters:
cre
- Name of the recruiting creature.number
- Number of creature- Returns:
- A List of all Terrains where recruitment is possible.
-
getAllThatThisCreatureCanRecruit
A list of what a creature can recruit. -
getAllThatCanRecruitThisCreature
A list of what can recruit a creature. -
getRecruitFromRecruiterTerrainNumber
public CreatureType getRecruitFromRecruiterTerrainNumber(CreatureType cre, MasterBoardTerrain t, int number) Return the name of the recruit for the given number of the given recruiter in the given terrain, or null if there's none.- Parameters:
cre
- The recruiting creature.number
- Number of creaturet
- Terrain in which the recruiting may occur.- Returns:
- The recruit.
-
getBestPossibleRecruitEver
Return the name of the best possible creature that is reachable trough the given creature from the given LegionInfo (can be null).- Parameters:
cre
- The recruiting creature.legion
- The recruiting legion or null.- Returns:
- The best possible recruit.
-
isRecruitDistanceLessThan
Determine if a creature given by 'lesser' could potentially summon the higher valued creature given by 'greater' within N steps. This is used to determine if 'lesser' is redundant for mustering purposes if we have 'greater' Here we limit the search to 'distance' (typically 2) recruit steps since otherwise every creature is 'reachable' via a downmuster at the tower and starting all over which is not what we are interested in.- Parameters:
lesser
- Name of the recruiting creature.greater
- Name of the recruit we are trying to get todistance
- number of steps to consider
-