soc.robot
Class SOCPlayerTracker

java.lang.Object
  extended by soc.robot.SOCPlayerTracker

public class SOCPlayerTracker
extends java.lang.Object

This class is used by the SOCRobotBrain to track strategic planning information such as possible building spots for itself and other players. Also used for prediction of other players' possible upcoming moves.

Some users of this class are: SOCRobotDM.planStuff(int), and many callers of getWinGameETA()

(Dissertation excerpt)

"When a player places a road, that player's PlayerTracker will look ahead by pretending to place new roads attached to that road and then recording new potential settlements [and their roads]...

The PlayerTracker only needs to be updated when players put pieces on the board... not only when that player builds a road but when any player builds a road or settlement. This is because another player's road or settlement may cut off a path to a future settlement. This update can be done by keeping track of which pieces support the building of others."

To output a legible overview of the data in a SOCPlayerTracker, use playerTrackersDebug(HashMap).

Author:
Robert S Thomas

Field Summary
protected  SOCRobotBrain brain
          The robot brain using this tracker
protected static int EXPAND_LEVEL
          Road expansion level for addOurNewRoadOrShip(SOCRoad, HashMap, int); how far away to look for possible future settlements (level of recursion).
protected static int EXPAND_LEVEL_SHIP_EXTRA
          Ship route length expansion level to add to EXPAND_LEVEL for expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int).
(package private)  boolean inUse
          monitor for synchronization
protected  int knightsToBuy
           
protected  int largestArmyETA
           
protected  int longestRoadETA
           
protected static int LR_CALC_LEVEL
          Road expansion level for updateLRPotential(SOCPossibleRoad, SOCPlayer, SOCRoad, int, int); how far away to look for possible future roads (level of recursion).
protected  boolean needLA
           
protected  boolean needLR
           
protected  SOCSettlement pendingInitSettlement
          Player's settlement during initial placement; delay processing until the road is placed, and thus the settlement placement can't be moved around.
private  SOCPlayer player
          The player being tracked
private  int playerNumber
          Seat number of the player being tracked; player.getPlayerNumber()
protected  java.util.TreeMap<java.lang.Integer,SOCPossibleCity> possibleCities
          Key = Integer node coordinate, value = SOCPossibleCity
protected  java.util.TreeMap<java.lang.Integer,SOCPossibleRoad> possibleRoads
          Includes both roads and ships.
protected  java.util.TreeMap<java.lang.Integer,SOCPossibleSettlement> possibleSettlements
          Possible near-future settlements for this player.
protected  int roadsToGo
           
private  SOCShip scen_SC_PIRI_closestShipToFortress
          For scenario _SC_PIRI, the player's ship closest to the Fortress (the ship farthest west).
protected  int winGameETA
           
 
Constructor Summary
SOCPlayerTracker(SOCPlayer pl, SOCRobotBrain br)
          Constructor.
SOCPlayerTracker(SOCPlayerTracker pt)
          Copy constructor.
 
Method Summary
 void addNewRoadOrShip(SOCRoad road, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          add a road or ship that has just been built
 void addNewSettlement(SOCSettlement settlement, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          Add a settlement that has just been built.
 void addOurNewCity(SOCCity city)
          add one of our cities, by removing it from the possible-cities list if it's there.
private  void addOurNewRoadOrShip(SOCRoad road, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers, int expandLevel)
          Add one of our roads or ships that has just been built.
 void addOurNewSettlement(SOCSettlement settlement, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          Add one of our settlements, and newly possible pieces from it.
private  void addTheirNewRoadOrShip(SOCRoad road, boolean isCancel)
          add another player's new road or ship, or cancel our own bad road by acting as if another player has placed there.
 void addTheirNewSettlement(SOCSettlement settlement, boolean isCancel)
          add another player's new settlement, or cancel our own bad settlement by acting as if another player has placed there.
 void cancelWrongCity(SOCCity city)
          Remove our incorrect city placement, it's been rejected by the server.
 void cancelWrongRoadOrShip(SOCRoad road)
          Remove our incorrect road or ship placement, it's been rejected by the server.
 void cancelWrongSettlement(SOCSettlement settlement)
          Remove our incorrect settlement placement, it's been rejected by the server.
static java.util.HashMap<java.lang.Integer,SOCPlayerTracker> copyPlayerTrackers(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          make copies of player trackers and then make connections between copied pieces
 void expandRoadOrShip(SOCPossibleRoad targetRoad, SOCPlayer player, SOCPlayer dummy, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers, int level)
          Expand a possible road or ship, to see what placements it makes possible.
 SOCRobotBrain getBrain()
           
 int getKnightsToBuy()
          Get the number of knights needed to take Largest Army.
 int getLargestArmyETA()
          Get the ETA to take Largest Army.
 int getLongestRoadETA()
          Get the ETA to take Longest Road.
 SOCSettlement getPendingInitSettlement()
           
 SOCPlayer getPlayer()
           
 java.util.TreeMap<java.lang.Integer,SOCPossibleCity> getPossibleCities()
           
 java.util.TreeMap<java.lang.Integer,SOCPossibleRoad> getPossibleRoads()
          Get the possible roads and ships (SOCPossibleRoad, SOCPossibleShip).
 java.util.TreeMap<java.lang.Integer,SOCPossibleSettlement> getPossibleSettlements()
           
 int getRoadsToGo()
          Get how many roads must be built to take Longest Road.
 SOCShip getScenario_SC_PIRI_closestShipToFortress()
          For scenario _SC_PIRI, get the player's ship closest to their Fortress (the ship farthest west).
 int getScenario_SC_PIRI_shipDistanceToFortress(SOCShip ship)
          For scenario _SC_PIRI, get the distance of this player's closest ship from their SOCFortress.
 int getWinGameETA()
          Get the calculated Winning the Game ETA (WGETA), based on the most recent call to recalcWinGameETA().
 boolean needsLA()
          Does this player need Largest Army to win? Updated by recalcWinGameETA().
 boolean needsLR()
          Does this player need Longest Road to win? Updated by recalcWinGameETA().
static void playerTrackersDebug(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers)
          Print debug output for a set of player trackers.
 void recalcLargestArmyETA()
          calculate the largest army ETA
 void recalcLongestRoadETA()
          Calculate the longest road ETA.
private  int recalcLongestRoadETAAux(int startNode, int pathLength, int lrLength, int searchDepth)
          Does a depth first search from the end point of the longest path in a graph of nodes and returns how many roads would need to be built to take longest road.
(package private)  SOCPossibleShip recalcScenario_SC_PIRI_nextPotentialShip()
          For scenario _SC_PIRI, get the player's next potential ship towards their Fortress.
 void recalcWinGameETA()
          Recalculate the tracked player's ETA for winning the game (WGETA) by making and simulating with a copy of our current potential settlement/city locations, building speed estimates (BSEs), and dice numbers, looping from player's current SOCPlayer.getTotalVP() to SOCGame.vp_winner.
 void releaseMonitor()
          release the monitor for this tracker
protected  void removeDependents(SOCPossibleRoad road)
          remove everything that depends on this road being built
protected  void removeFromNecessaryRoads(SOCPossibleRoad pr)
          remove this piece from the pieces that support it
protected  void removeFromNecessaryRoads(SOCPossibleSettlement ps)
          remove this piece from the pieces that support it
 void setPendingInitSettlement(SOCSettlement s)
          set this player's pending initial settlement, to be placed/calculated by this tracker after their road.
 void takeMonitor()
          take the monitor for this tracker
 java.lang.String toString()
          SOCPlayerTracker key fields (brain player name, tracked player name) to aid debugging.
static java.util.HashMap<java.lang.Integer,SOCPlayerTracker> tryPutPiece(SOCPlayingPiece piece, SOCGame game, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          See how building a piece impacts the game.
static void tryPutPieceNoCopy(SOCPlayingPiece piece, SOCGame game, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          Same as tryPutPiece, but we don't make a copy of the player trackers.
 void undoAddOurNewCity(SOCPossibleCity city)
          undo adding one of our cities
static void undoTryPutPiece(SOCPlayingPiece piece, SOCGame game)
          Reset the game back to before we put the temp piece
 void updateLRPotential(SOCPossibleRoad posRoad, SOCPlayer dummy, SOCRoad dummyRoad, int lrLength, int level)
          update the potential LR value of a possible road or ship by placing dummy roads/ships and calculating LR (longest road).
 void updateLRValues()
          update the longest road values for all possible roads/ships.
(package private)  void updateScenario_SC_PIRI_closestShipToFortress(SOCShip ship, boolean shipAdded)
          For scenario _SC_PIRI, update the player's ship closest to their Fortress.
protected  void updateSettlementConflicts(SOCPossibleSettlement ps, java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          update settlement conflicts
 void updateThreats(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
          update threats for pieces that need to be updated
static void updateWinGameETAs(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers)
          Update winGameETAs for player trackers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXPAND_LEVEL

protected static int EXPAND_LEVEL
Road expansion level for addOurNewRoadOrShip(SOCRoad, HashMap, int); how far away to look for possible future settlements (level of recursion).


EXPAND_LEVEL_SHIP_EXTRA

protected static int EXPAND_LEVEL_SHIP_EXTRA
Ship route length expansion level to add to EXPAND_LEVEL for expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int).

Since:
2.0.00

LR_CALC_LEVEL

protected static int LR_CALC_LEVEL
Road expansion level for updateLRPotential(SOCPossibleRoad, SOCPlayer, SOCRoad, int, int); how far away to look for possible future roads (level of recursion).


brain

protected final SOCRobotBrain brain
The robot brain using this tracker


player

private final SOCPlayer player
The player being tracked


playerNumber

private final int playerNumber
Seat number of the player being tracked; player.getPlayerNumber()


possibleSettlements

protected java.util.TreeMap<java.lang.Integer,SOCPossibleSettlement> possibleSettlements
Possible near-future settlements for this player. Key = Integer node coordinate, value = SOCPossibleSettlement. Expanded in addOurNewRoadOrShip(SOCRoad, HashMap, int) via expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int). Also updated in addNewSettlement(SOCSettlement, HashMap), cancelWrongSettlement(SOCSettlement), a few other places.


possibleRoads

protected java.util.TreeMap<java.lang.Integer,SOCPossibleRoad> possibleRoads
Includes both roads and ships. Key = Integer edge coordinate, value = SOCPossibleRoad or SOCPossibleShip Expanded in addOurNewRoadOrShip(SOCRoad, HashMap, int) via expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int).


possibleCities

protected java.util.TreeMap<java.lang.Integer,SOCPossibleCity> possibleCities
Key = Integer node coordinate, value = SOCPossibleCity


longestRoadETA

protected int longestRoadETA

roadsToGo

protected int roadsToGo

largestArmyETA

protected int largestArmyETA

winGameETA

protected int winGameETA

knightsToBuy

protected int knightsToBuy

needLR

protected boolean needLR

needLA

protected boolean needLA

pendingInitSettlement

protected SOCSettlement pendingInitSettlement
Player's settlement during initial placement; delay processing until the road is placed, and thus the settlement placement can't be moved around.


scen_SC_PIRI_closestShipToFortress

private SOCShip scen_SC_PIRI_closestShipToFortress
For scenario _SC_PIRI, the player's ship closest to the Fortress (the ship farthest west). null otherwise. Updated by updateScenario_SC_PIRI_closestShipToFortress(SOCShip, boolean).

Since:
2.0.00

inUse

boolean inUse
monitor for synchronization

Constructor Detail

SOCPlayerTracker

public SOCPlayerTracker(SOCPlayer pl,
                        SOCRobotBrain br)
Constructor.

Parameters:
pl - the player being tracked
br - the robot brain using this tracker

SOCPlayerTracker

public SOCPlayerTracker(SOCPlayerTracker pt)
Copy constructor.

Note: Does NOT copy connections between possible pieces

Parameters:
pt - the player tracker
Method Detail

copyPlayerTrackers

public static java.util.HashMap<java.lang.Integer,SOCPlayerTracker> copyPlayerTrackers(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
make copies of player trackers and then make connections between copied pieces

Note: not copying threats param trackers player trackers for each player


takeMonitor

public void takeMonitor()
take the monitor for this tracker


releaseMonitor

public void releaseMonitor()
release the monitor for this tracker


getBrain

public SOCRobotBrain getBrain()
Returns:
the robot brain for this tracker

getPlayer

public SOCPlayer getPlayer()
Returns:
the player for this tracker

getPossibleRoads

public java.util.TreeMap<java.lang.Integer,SOCPossibleRoad> getPossibleRoads()
Get the possible roads and ships (SOCPossibleRoad, SOCPossibleShip). Treat the structure of the returned map as read-only, don't add or remove anything.

Returns:
the Map of coordinates to possible roads and ships

getPossibleSettlements

public java.util.TreeMap<java.lang.Integer,SOCPossibleSettlement> getPossibleSettlements()
Returns:
the list of possible settlements

getPossibleCities

public java.util.TreeMap<java.lang.Integer,SOCPossibleCity> getPossibleCities()
Returns:
the list of possible cities

getLongestRoadETA

public int getLongestRoadETA()
Get the ETA to take Longest Road. Updated in updateWinGameETAs(HashMap) or recalcLongestRoadETA().

Returns:
the longest road eta
See Also:
needsLR(), getRoadsToGo()

getRoadsToGo

public int getRoadsToGo()
Get how many roads must be built to take Longest Road. Updated in updateWinGameETAs(HashMap) and recalcLongestRoadETA().

Returns:
how many roads needed to build to take longest road
See Also:
needsLR(), getLongestRoadETA()

getLargestArmyETA

public int getLargestArmyETA()
Get the ETA to take Largest Army. Updated in updateWinGameETAs(HashMap) and recalcLargestArmyETA().

Returns:
largest army eta
See Also:
needsLA(), getKnightsToBuy()

getKnightsToBuy

public int getKnightsToBuy()
Get the number of knights needed to take Largest Army. Updated in updateWinGameETAs(HashMap) and recalcLargestArmyETA().

Returns:
the number of knights to buy to get LA
See Also:
needsLA(), getLargestArmyETA()

getPendingInitSettlement

public SOCSettlement getPendingInitSettlement()
Returns:
the pending-placement initial settlement

setPendingInitSettlement

public void setPendingInitSettlement(SOCSettlement s)
set this player's pending initial settlement, to be placed/calculated by this tracker after their road.

You must call addNewSettlement and then addNewRoadOrShip: This is just a place to store the settlement data.

Parameters:
s - Settlement, or null

addNewRoadOrShip

public void addNewRoadOrShip(SOCRoad road,
                             java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
add a road or ship that has just been built

Parameters:
road - the road or ship
trackers - player trackers for the players

cancelWrongRoadOrShip

public void cancelWrongRoadOrShip(SOCRoad road)
Remove our incorrect road or ship placement, it's been rejected by the server.

Parameters:
road - Location of our bad road or ship
See Also:
SOCRobotBrain.cancelWrongPiecePlacement(SOCCancelBuildRequest)

addOurNewRoadOrShip

private void addOurNewRoadOrShip(SOCRoad road,
                                 java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers,
                                 int expandLevel)
Add one of our roads or ships that has just been built. Look for new adjacent possible settlements. Calls expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int) on newly possible adjacent roads or ships.

Parameters:
road - the road or ship
trackers - player trackers for the players
expandLevel - how far out we should expand roads/ships; passed to expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int)

expandRoadOrShip

public void expandRoadOrShip(SOCPossibleRoad targetRoad,
                             SOCPlayer player,
                             SOCPlayer dummy,
                             java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers,
                             int level)
Expand a possible road or ship, to see what placements it makes possible. Adds to or updates possibleSettlements at targetRoad's nodes, if potential. If level > 0, calls itself recursively to go more levels out from the current pieces, adding/updating possibleRoads and possibleSettlements.

Scenario _SC_PIRI: Ships in this scenario never expand east (never away from the pirate fortress). Scenario rules require the route to be as short as possible. Even if a human player might want to do so, it couldn't interfere with the bot's own route, so we don't track that possibility.

Parameters:
targetRoad - the possible road
player - the player who owns the original road
dummy - the dummy player used to see what's legal
trackers - player trackers
level - how many levels (additional pieces) to expand; 0 to only check targetRoad for potential settlements and not expand past it for new roads, ships, or further settlements

addTheirNewRoadOrShip

private void addTheirNewRoadOrShip(SOCRoad road,
                                   boolean isCancel)
add another player's new road or ship, or cancel our own bad road by acting as if another player has placed there. (That way, we won't decide to place there again.)

Parameters:
road - the new road or ship
isCancel - Is this our own robot's road placement, rejected by the server? If so, this method call will cancel its placement within the tracker data.

getScenario_SC_PIRI_closestShipToFortress

public SOCShip getScenario_SC_PIRI_closestShipToFortress()
For scenario _SC_PIRI, get the player's ship closest to their Fortress (the ship farthest west). Updated by updateScenario_SC_PIRI_closestShipToFortress(SOCShip, boolean).

Returns:
the closest ship in scenario _SC_PIRI; null otherwise.
Since:
2.0.00
See Also:
getScenario_SC_PIRI_shipDistanceToFortress(SOCShip)

updateScenario_SC_PIRI_closestShipToFortress

void updateScenario_SC_PIRI_closestShipToFortress(SOCShip ship,
                                                  boolean shipAdded)
                                            throws java.lang.IllegalArgumentException
For scenario _SC_PIRI, update the player's ship closest to their Fortress. Assumes no ship will ever be west of the fortress (smaller column number). Must be called after adding or removing a ship from our player's SOCPlayer.getRoads().

Parameters:
ship - Ship that was added or removed, or null to check all ships after removal
shipAdded - True if ship was added; false if ship or any other ship was removed or if we're updating Closest Ship without adding or removing a ship
Throws:
java.lang.IllegalArgumentException - if shipAdded is true, but null ship
Since:
2.0.00

getScenario_SC_PIRI_shipDistanceToFortress

public int getScenario_SC_PIRI_shipDistanceToFortress(SOCShip ship)
For scenario _SC_PIRI, get the distance of this player's closest ship from their SOCFortress. Since ships aren't placed diagonally, this is the distance along rows + columns. The edge (r,c) has node (r,c) as its left end, at distance 0.

Parameters:
ship - Any ship, including getScenario_SC_PIRI_closestShipToFortress()
Returns:
row distance + column distance based on piece coordinates; or 0 if no fortress which would mean the fortress was reached (distance 0) and defeated already.
Since:
2.0.00

recalcScenario_SC_PIRI_nextPotentialShip

SOCPossibleShip recalcScenario_SC_PIRI_nextPotentialShip()
For scenario _SC_PIRI, get the player's next potential ship towards their Fortress. If fortress was already defeated, or they have no boats, returns null.

This is calculated every time, not cached, because potential-ships list may change often. Calls updateScenario_SC_PIRI_closestShipToFortress(SOCShip, boolean) if closest ship not known.

Returns:
Next potential ship, or null
Since:
2.0.00

updateSettlementConflicts

protected void updateSettlementConflicts(SOCPossibleSettlement ps,
                                         java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
update settlement conflicts

Parameters:
ps - a possible settlement
trackers - player trackers for all players

addNewSettlement

public void addNewSettlement(SOCSettlement settlement,
                             java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
Add a settlement that has just been built. Called only after SOCGame.putPiece(SOCPlayingPiece) or SOCGame.putTempPiece(SOCPlayingPiece).

Parameters:
settlement - the settlement
trackers - player trackers for the players

cancelWrongSettlement

public void cancelWrongSettlement(SOCSettlement settlement)
Remove our incorrect settlement placement, it's been rejected by the server.

Parameters:
settlement - Location of our bad settlement
See Also:
SOCRobotBrain.cancelWrongPiecePlacement(SOCCancelBuildRequest)

addOurNewSettlement

public void addOurNewSettlement(SOCSettlement settlement,
                                java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
Add one of our settlements, and newly possible pieces from it. Adds a new possible city; removes conflicting possible settlements (ours or other players). On the large Sea board, if this is a coastal settlement adds newly possible ships, and if we've just settled a new island, newly possible roads, because the coastal settlement is a roads <-> ships transition.

Newly possible roads or ships next to the settlement are expanded by calling expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int). EXPAND_LEVEL is the basic expansion length, and ships add EXPAND_LEVEL_SHIP_EXTRA to that for crossing the sea to nearby islands.

Called in 2 different conditions:

Parameters:
settlement - the new settlement
trackers - player trackers for all of the players

addTheirNewSettlement

public void addTheirNewSettlement(SOCSettlement settlement,
                                  boolean isCancel)
add another player's new settlement, or cancel our own bad settlement by acting as if another player has placed there. (That way, we won't decide to place there again.)

Parameters:
settlement - the new settlement
isCancel - Is this our own robot's settlement placement, rejected by the server? If so, this method call will cancel its placement within the tracker data.

removeDependents

protected void removeDependents(SOCPossibleRoad road)
remove everything that depends on this road being built

Parameters:
road - the road

removeFromNecessaryRoads

protected void removeFromNecessaryRoads(SOCPossibleRoad pr)
remove this piece from the pieces that support it

Parameters:
pr - the possible road

removeFromNecessaryRoads

protected void removeFromNecessaryRoads(SOCPossibleSettlement ps)
remove this piece from the pieces that support it

Parameters:
ps - the possible settlement

cancelWrongCity

public void cancelWrongCity(SOCCity city)
Remove our incorrect city placement, it's been rejected by the server.

Note, there is no addNewCity or addTheirNewCity method.

Parameters:
city - Location of our bad city
See Also:
SOCRobotBrain.cancelWrongPiecePlacement(SOCCancelBuildRequest)

addOurNewCity

public void addOurNewCity(SOCCity city)
add one of our cities, by removing it from the possible-cities list if it's there. Note, there is no addNewCity or addTheirNewCity method.

Parameters:
city - the new city

undoAddOurNewCity

public void undoAddOurNewCity(SOCPossibleCity city)
undo adding one of our cities

Parameters:
city - the now possible city

updateThreats

public void updateThreats(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
update threats for pieces that need to be updated

Parameters:
trackers - all of the player trackers

recalcLongestRoadETA

public void recalcLongestRoadETA()
Calculate the longest road ETA. Always 500 or more if SOCGameOption.K_SC_0RVP is set. Updates fields for getLongestRoadETA() and getRoadsToGo().


recalcLongestRoadETAAux

private int recalcLongestRoadETAAux(int startNode,
                                    int pathLength,
                                    int lrLength,
                                    int searchDepth)
Does a depth first search from the end point of the longest path in a graph of nodes and returns how many roads would need to be built to take longest road.

Do not call if SOCGameOption.K_SC_0RVP is set.

Parameters:
startNode - the path endpoint
pathLength - the length of that path
lrLength - length of longest road in the game
searchDepth - how many roads out to search
Returns:
the number of roads needed, or 500 if it can't be done

recalcLargestArmyETA

public void recalcLargestArmyETA()
calculate the largest army ETA


updateLRValues

public void updateLRValues()
update the longest road values for all possible roads/ships.

longest road value is how much this road/ship would increase our longest road if it were built.

the longest road potential is how much this road/ship would increase our LR value if other roads supported by this one were built.


updateLRPotential

public void updateLRPotential(SOCPossibleRoad posRoad,
                              SOCPlayer dummy,
                              SOCRoad dummyRoad,
                              int lrLength,
                              int level)
update the potential LR value of a possible road or ship by placing dummy roads/ships and calculating LR (longest road). If level > 0, add the new roads or ships adjacent to dummy and recurse.

Parameters:
posRoad - the possible road or ship
dummy - the dummy player
lrLength - the current LR length
level - how many levels of recursion, or 0 to not recurse

getWinGameETA

public int getWinGameETA()
Get the calculated Winning the Game ETA (WGETA), based on the most recent call to recalcWinGameETA().

Returns:
the ETA for winning the game

needsLR

public boolean needsLR()
Does this player need Longest Road to win? Updated by recalcWinGameETA().

Returns:
true if this player needs LR to win
See Also:
getLongestRoadETA(), getRoadsToGo()

needsLA

public boolean needsLA()
Does this player need Largest Army to win? Updated by recalcWinGameETA().

Returns:
true if this player needs LA to win
See Also:
getLargestArmyETA(), getKnightsToBuy()

recalcWinGameETA

public void recalcWinGameETA()
Recalculate the tracked player's ETA for winning the game (WGETA) by making and simulating with a copy of our current potential settlement/city locations, building speed estimates (BSEs), and dice numbers, looping from player's current SOCPlayer.getTotalVP() to SOCGame.vp_winner.

Calculates the fields for getWinGameETA(), needsLA(), needsLR().

Each time through the loop, given potential locations and available pieces, pick the fastest ETA among each of these 2-VP combinations:

The temporary potential sets, port trade flags, BSEs and dice numbers are updated with the picked pieces. The loop body doesn't add new potential roads/ships or potential settlements to its copy of those sets, or call expandRoadOrShip(SOCPossibleRoad, SOCPlayer, SOCPlayer, HashMap, int), so it may run out of potential locations before vp_winner is reached. If the loop doesn't have the locations or pieces to do anything, 500 ETA and 2 VP are added to the totals to keep things moving.

If the loop reaches SOCGame.vp_winner - 1, it calculates ETAs for 1 city or settlement (+ roads) instead of 2, and Largest Army and Longest Road, to make its choice.


tryPutPiece

public static java.util.HashMap<java.lang.Integer,SOCPlayerTracker> tryPutPiece(SOCPlayingPiece piece,
                                                                                SOCGame game,
                                                                                java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
See how building a piece impacts the game. Calls SOCGame.putTempPiece(SOCPlayingPiece) and copyPlayerTrackers(HashMap), then adds piece to the tracker copies.

Parameters:
piece - the piece to build
game - the game
trackers - the player trackers
Returns:
a copy of the player trackers with the new piece in place
See Also:
tryPutPieceNoCopy(SOCPlayingPiece, SOCGame, HashMap)

tryPutPieceNoCopy

public static void tryPutPieceNoCopy(SOCPlayingPiece piece,
                                     SOCGame game,
                                     java.util.HashMap<java.lang.Integer,SOCPlayerTracker> trackers)
Same as tryPutPiece, but we don't make a copy of the player trackers. Instead caller supplies the copy.

Parameters:
piece - the piece to build
game - the game
trackers - the already-copied player trackers

undoTryPutPiece

public static void undoTryPutPiece(SOCPlayingPiece piece,
                                   SOCGame game)
Reset the game back to before we put the temp piece

Parameters:
piece - the piece to remove
game - the game

playerTrackersDebug

public static void playerTrackersDebug(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers)
Print debug output for a set of player trackers.

Calls D.ebugPrintln; no output will appear if this class imports soc.disableDebug.D instead of soc.debug.D.

Parameters:
playerTrackers - the player trackers

updateWinGameETAs

public static void updateWinGameETAs(java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers)
Update winGameETAs for player trackers. For each tracker, call recalcLongestRoadETA(), recalcLargestArmyETA(), recalcWinGameETA().

Parameters:
playerTrackers - the player trackers

toString

public java.lang.String toString()
SOCPlayerTracker key fields (brain player name, tracked player name) to aid debugging. Since PTs are copied a lot and we need a way to tell the copies apart, also includes hex super.hashCode().

Overrides:
toString in class java.lang.Object
Returns:
This SOCPlayerTracker's fields, in the format: SOCPlayerTracker@hashCode[brainPlayerName, pl=trackedPlayerName]
Since:
1.1.20