net.sf.colossus.game
Class RecruitGraph

java.lang.Object
  extended by net.sf.colossus.game.RecruitGraph

public class RecruitGraph
extends java.lang.Object

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
private static class RecruitGraph.RecruitEdge
          The edge of the Recruit Graph
static class RecruitGraph.RecruitOption
          Models a recruit option for a given creature.
private static class RecruitGraph.RecruitVertex
          The vertex of the Recruit Graph
 
Field Summary
private  java.util.List<RecruitGraph.RecruitEdge> allEdge
           
private  java.util.List<RecruitGraph.RecruitVertex> allVertex
           
static int BIGNUM
          99 creatures can muster one means: can not muster at all
private  Caretaker caretaker
           
private  java.util.Map<java.lang.String,RecruitGraph.RecruitVertex> creatureToVertex
           
private static java.util.logging.Logger LOGGER
           
private  IVariantKnower variantKnower
           
 
Constructor Summary
RecruitGraph(IVariantKnower variantKnower)
           
 
Method Summary
private  RecruitGraph.RecruitEdge addEdge(RecruitGraph.RecruitVertex src, RecruitGraph.RecruitVertex dst, int number, MasterBoardTerrain terrain)
           
 void addEdge(java.lang.String src, java.lang.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.RecruitVertex addVertex(java.lang.String cre)
           
 void clear()
          Clear the graph of all Vertex & Edge.
 java.util.List<MasterBoardTerrain> getAllTerrainsWhereThisNumberOfCreatureRecruit(java.lang.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.
 java.util.List<RecruitGraph.RecruitOption> getAllThatCanRecruitThisCreature(java.lang.String cre)
          A list of what can recruit a creature.
 java.util.List<RecruitGraph.RecruitOption> getAllThatThisCreatureCanRecruit(java.lang.String cre)
          A list of what a creature can recruit.
 CreatureType getBestPossibleRecruitEver(java.lang.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 getCaretaker()
           
private  java.util.List<RecruitGraph.RecruitEdge> getIncomingEdges(java.lang.String cre)
          Give the List of RecruitEdge where the given creature is the destination.
 int getMaximumUsefulNumber(java.lang.String cre)
          What is the maximum "useful" number of a given creature for recruitment purpose (excluding "Any" or "AnyNonLord").
private  java.util.List<RecruitGraph.RecruitEdge> getOutgoingEdges(java.lang.String cre)
          Give the List of RecruitEdge where the given creature is the source.
 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.
private  Variant getVariant()
           
private  RecruitGraph.RecruitVertex getVertex(java.lang.String cre)
           
 boolean isRecruitDistanceLessThan(java.lang.String lesser, java.lang.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(java.lang.String recruiter, java.lang.String recruit, MasterBoardTerrain terrain, MasterHex hex)
           
 void setCaretaker(Caretaker caretaker)
          Set the Caretaker to use for availability of creatures.
private  java.util.List<RecruitGraph.RecruitVertex> traverse(RecruitGraph.RecruitVertex s, java.util.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).
private  java.util.List<RecruitGraph.RecruitVertex> traverse(java.lang.String cre, Legion legion)
          Give the List of RecruitVertex still reachable through the given creature from the given Legion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

caretaker

private Caretaker caretaker

variantKnower

private final IVariantKnower variantKnower

allVertex

private final java.util.List<RecruitGraph.RecruitVertex> allVertex

allEdge

private final java.util.List<RecruitGraph.RecruitEdge> allEdge

creatureToVertex

private final java.util.Map<java.lang.String,RecruitGraph.RecruitVertex> creatureToVertex

BIGNUM

public static final int BIGNUM
99 creatures can muster one means: can not muster at all

See Also:
Constant Field Values
Constructor Detail

RecruitGraph

public RecruitGraph(IVariantKnower variantKnower)
Method Detail

addVertex

private RecruitGraph.RecruitVertex addVertex(java.lang.String cre)

getVertex

private RecruitGraph.RecruitVertex getVertex(java.lang.String cre)

addEdge

private RecruitGraph.RecruitEdge addEdge(RecruitGraph.RecruitVertex src,
                                         RecruitGraph.RecruitVertex dst,
                                         int number,
                                         MasterBoardTerrain terrain)

traverse

private java.util.List<RecruitGraph.RecruitVertex> traverse(RecruitGraph.RecruitVertex s,
                                                            java.util.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 vertex
visited - Already visited vertexes
legion - The legion to use for availability
Returns:
The list of all reachable Vertex from parameter s.

getCaretaker

Caretaker getCaretaker()

getVariant

private Variant getVariant()

getOutgoingEdges

private java.util.List<RecruitGraph.RecruitEdge> getOutgoingEdges(java.lang.String cre)
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

private java.util.List<RecruitGraph.RecruitEdge> getIncomingEdges(java.lang.String cre)
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

private java.util.List<RecruitGraph.RecruitVertex> traverse(java.lang.String cre,
                                                            Legion legion)
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

public void addEdge(java.lang.String src,
                    java.lang.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.

Parameters:
src - Name of the recruiting creature
dst - Name of the recruited creature
number - Number of recruiters
terrain - Terrain where the recruiting occurs

numberOfRecruiterNeeded

public int numberOfRecruiterNeeded(java.lang.String recruiter,
                                   java.lang.String recruit,
                                   MasterBoardTerrain terrain,
                                   MasterHex hex)

setCaretaker

public void setCaretaker(Caretaker caretaker)
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

public int getMaximumUsefulNumber(java.lang.String cre)
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 java.util.List<MasterBoardTerrain> getAllTerrainsWhereThisNumberOfCreatureRecruit(java.lang.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

public java.util.List<RecruitGraph.RecruitOption> getAllThatThisCreatureCanRecruit(java.lang.String cre)
A list of what a creature can recruit.


getAllThatCanRecruitThisCreature

public java.util.List<RecruitGraph.RecruitOption> getAllThatCanRecruitThisCreature(java.lang.String cre)
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 creature
t - Terrain in which the recruiting may occur.
Returns:
The recruit.

getBestPossibleRecruitEver

public CreatureType getBestPossibleRecruitEver(java.lang.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).

Parameters:
cre - The recruiting creature.
legion - The recruiting legion or null.
Returns:
The best possible recruit.

isRecruitDistanceLessThan

public boolean isRecruitDistanceLessThan(java.lang.String lesser,
                                         java.lang.String greater,
                                         int distance)
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 to
distance - number of steps to consider