Class RecruitGraph

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

public class RecruitGraph extends 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
  • Field Details

  • Constructor Details

  • Method Details

    • addVertex

      private RecruitGraph.RecruitVertex addVertex(String cre)
    • getVertex

      private RecruitGraph.RecruitVertex getVertex(String cre)
    • addEdge

    • traverse

      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 List<RecruitGraph.RecruitEdge> getOutgoingEdges(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 List<RecruitGraph.RecruitEdge> getIncomingEdges(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 List<RecruitGraph.RecruitVertex> traverse(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(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.
      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(String recruiter, 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 invalid input: '&' Edge.
    • getMaximumUsefulNumber

      public int getMaximumUsefulNumber(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 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

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

      public List<RecruitGraph.RecruitOption> getAllThatCanRecruitThisCreature(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.
      t - Terrain in which the recruiting may occur.
      number - Number of creature
      Returns:
      The recruit.
    • getBestPossibleRecruitEver

      public CreatureType 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).
      Parameters:
      cre - The recruiting creature.
      legion - The recruiting legion or null.
      Returns:
      The best possible recruit.
    • isRecruitDistanceLessThan

      public 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. 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