soc.robot
Class SOCBuildingSpeedEstimate

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

public class SOCBuildingSpeedEstimate
extends java.lang.Object

This class calculates approximately how long it would take a player to build something. Uses SOCPlayerNumbers to get resources of currently reached hexes.


Field Summary
static int CARD
           
static int CITY
           
static int DEFAULT_ROLL_LIMIT
           
(package private)  int[] estimatesFromNothing
           
(package private)  int[] estimatesFromNow
           
static int MAXPLUSONE
           
static int MIN
           
protected static boolean recalc
           
private  SOCResourceSet[] resourcesForRoll
          Resource sets gained for each dice roll number (2 to 12).
static int ROAD
           
private  int[] rollsPerResource
          Number of rolls to gain each resource type (SOCResourceConstants.CLAY to SOCResourceConstants.WOOD).
static int SETTLEMENT
           
static int SHIP
           
 
Constructor Summary
SOCBuildingSpeedEstimate()
          Create a new SOCBuildingSpeedEstimate, not yet calculating estimates.
SOCBuildingSpeedEstimate(SOCPlayerNumbers numbers)
          Create a new SOCBuildingSpeedEstimate, calculating the rollsPerResource and resourcesPerRoll based on the player's dice numbers (settlement/city hexes).
 
Method Summary
protected  SOCResSetBuildTimePair calculateRollsAccurate(SOCResourceSet startingResources, SOCResourceSet targetResources, int cutoff, boolean[] ports)
          this figures out how many rolls it would take this player to get the target set of resources given a starting set
protected  SOCResSetBuildTimePair calculateRollsAndRsrcFast(SOCResourceSet startingResources, SOCResourceSet targetResources, int cutoff, boolean[] ports)
          this figures out how many rolls it would take this player to get the target set of resources given a starting set
protected  int calculateRollsFast(SOCResourceSet startingResources, SOCResourceSet targetResources, int cutoff, boolean[] ports)
          Figures out how many rolls it would take this player to get the target set of resources, given a starting set.
 int[] getEstimatesFromNothingAccurate(boolean[] ports)
           
 int[] getEstimatesFromNothingFast(boolean[] ports)
           
 int[] getEstimatesFromNothingFast(boolean[] ports, int limit)
           
 int[] getEstimatesFromNowAccurate(SOCResourceSet resources, boolean[] ports)
           
 int[] getEstimatesFromNowFast(SOCResourceSet resources, boolean[] ports)
           
static int[] getRollsForResourcesSorted(SOCPlayer pl)
          Estimate the rolls for this player to obtain each resource.
 int[] getRollsPerResource()
          Get the number of rolls to gain each resource type (SOCResourceConstants.CLAY to SOCResourceConstants.WOOD).
 void recalculateEstimates(SOCPlayerNumbers numbers)
          recalculate both rollsPerResource and resourcesPerRoll
 void recalculateEstimates(SOCPlayerNumbers numbers, int robberHex)
          Recalculate both rollsPerResource and resourcesPerRoll, optionally considering the robber's location.
 void recalculateResourcesForRoll(SOCPlayerNumbers numbers, int robberHex)
          Calculate what resources this player will get on each die roll, optionally taking the robber into account.
 void recalculateRollsPerResource(SOCPlayerNumbers numbers, int robberHex)
          Calculate the rollsPerResource estimates, optionally considering the robber's location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROAD

public static final int ROAD
See Also:
Constant Field Values

SETTLEMENT

public static final int SETTLEMENT
See Also:
Constant Field Values

CITY

public static final int CITY
See Also:
Constant Field Values

CARD

public static final int CARD
See Also:
Constant Field Values

SHIP

public static final int SHIP
See Also:
Constant Field Values

MIN

public static final int MIN
See Also:
Constant Field Values

MAXPLUSONE

public static final int MAXPLUSONE
See Also:
Constant Field Values

DEFAULT_ROLL_LIMIT

public static final int DEFAULT_ROLL_LIMIT
See Also:
Constant Field Values

recalc

protected static boolean recalc

estimatesFromNothing

int[] estimatesFromNothing

estimatesFromNow

int[] estimatesFromNow

rollsPerResource

private int[] rollsPerResource
Number of rolls to gain each resource type (SOCResourceConstants.CLAY to SOCResourceConstants.WOOD). Index 0 is unused.

Does not contain GOLD_HEX or SOCResourceConstants.GOLD_LOCAL, because SOCPlayerNumbers methods translate the gold hexes into each of the normal 5 resource types.


resourcesForRoll

private SOCResourceSet[] resourcesForRoll
Resource sets gained for each dice roll number (2 to 12). Indexes 0 and 1 are unused.

Does not contain GOLD_HEX or SOCResourceConstants.GOLD_LOCAL, because SOCPlayerNumbers methods translate each gold hex number into 1 resource of each of the normal 5 types.

Constructor Detail

SOCBuildingSpeedEstimate

public SOCBuildingSpeedEstimate(SOCPlayerNumbers numbers)
Create a new SOCBuildingSpeedEstimate, calculating the rollsPerResource and resourcesPerRoll based on the player's dice numbers (settlement/city hexes).

Parameters:
numbers - the numbers that the player's pieces are touching

SOCBuildingSpeedEstimate

public SOCBuildingSpeedEstimate()
Create a new SOCBuildingSpeedEstimate, not yet calculating estimates. To consider the player's dice numbers (settlement/city hexes), you'll need to call recalculateEstimates(SOCPlayerNumbers, int).

Method Detail

getRollsForResourcesSorted

public static final int[] getRollsForResourcesSorted(SOCPlayer pl)
Estimate the rolls for this player to obtain each resource. Will construct a SOCBuildingSpeedEstimate from pl.getNumbers(), and call getRollsPerResource().

Parameters:
pl - Player to check numbers
Returns:
Resource order, sorted by rolls per resource descending; a 5-element array containing SOCResourceConstants.CLAY, SOCResourceConstants.WHEAT, etc, where the resource in [0] has the highest rolls per resource.
Since:
2.0.00

getEstimatesFromNothingAccurate

public int[] getEstimatesFromNothingAccurate(boolean[] ports)
Parameters:
ports - the port flags for the player
Returns:
the estimates from nothing

getEstimatesFromNothingFast

public int[] getEstimatesFromNothingFast(boolean[] ports)
Parameters:
ports - the port flags for the player
Returns:
the estimates from nothing

getEstimatesFromNothingFast

public int[] getEstimatesFromNothingFast(boolean[] ports,
                                         int limit)
Parameters:
ports - the port flags for the player
Returns:
the estimates from nothing

getEstimatesFromNowAccurate

public int[] getEstimatesFromNowAccurate(SOCResourceSet resources,
                                         boolean[] ports)
Parameters:
resources - the player's current resources
ports - the player's port flags
Returns:
the estimates from now

getEstimatesFromNowFast

public int[] getEstimatesFromNowFast(SOCResourceSet resources,
                                     boolean[] ports)
Parameters:
resources - the player's current resources
ports - the player's port flags
Returns:
the estimates from now

recalculateEstimates

public void recalculateEstimates(SOCPlayerNumbers numbers)
recalculate both rollsPerResource and resourcesPerRoll

Parameters:
numbers - the numbers that the player is touching
See Also:
recalculateEstimates(SOCPlayerNumbers, int)

recalculateEstimates

public void recalculateEstimates(SOCPlayerNumbers numbers,
                                 int robberHex)
Recalculate both rollsPerResource and resourcesPerRoll, optionally considering the robber's location.

Parameters:
numbers - the numbers that the player is touching
robberHex - Robber location from SOCBoard.getRobberHex(), or -1 to ignore the robber
See Also:
recalculateEstimates(SOCPlayerNumbers)

recalculateRollsPerResource

public void recalculateRollsPerResource(SOCPlayerNumbers numbers,
                                        int robberHex)
Calculate the rollsPerResource estimates, optionally considering the robber's location.

Parameters:
numbers - the numbers that the player is touching
robberHex - Robber location from SOCBoard.getRobberHex(), or -1 to ignore the robber

recalculateResourcesForRoll

public void recalculateResourcesForRoll(SOCPlayerNumbers numbers,
                                        int robberHex)
Calculate what resources this player will get on each die roll, optionally taking the robber into account.

Parameters:
numbers - the numbers that the player is touching
robberHex - Robber location from SOCBoard.getRobberHex(), or -1 to ignore the robber

getRollsPerResource

public int[] getRollsPerResource()
Get the number of rolls to gain each resource type (SOCResourceConstants.CLAY to SOCResourceConstants.WOOD).

Does not contain GOLD_HEX or SOCResourceConstants.GOLD_LOCAL, because SOCPlayerNumbers methods translate the gold hexes into each of the normal 5 resource types.

Returns:
the rolls per resource results; index 0 is unused.

calculateRollsFast

protected final int calculateRollsFast(SOCResourceSet startingResources,
                                       SOCResourceSet targetResources,
                                       int cutoff,
                                       boolean[] ports)
Figures out how many rolls it would take this player to get the target set of resources, given a starting set.

This method does the same calculation as calculateRollsAndRsrcFast(SOCResourceSet, SOCResourceSet, int, boolean[]) with a simpler return type and no thrown exception.

Parameters:
startingResources - the starting resources
targetResources - the target resources
cutoff - maximum number of rolls
ports - a list of port flags
Returns:
the number of rolls, or cutoff if that maximum is reached. If startingResources.contains(targetResources), returns 0.
Since:
2.0.00

calculateRollsAndRsrcFast

protected SOCResSetBuildTimePair calculateRollsAndRsrcFast(SOCResourceSet startingResources,
                                                           SOCResourceSet targetResources,
                                                           int cutoff,
                                                           boolean[] ports)
                                                    throws CutoffExceededException
this figures out how many rolls it would take this player to get the target set of resources given a starting set

Before v2.0.00, this was calculateRollsFast.

Parameters:
startingResources - the starting resources
targetResources - the target resources
cutoff - throw an exception if the total speed is greater than this
ports - a list of port flags
Returns:
the number of rolls, and startingResources after any trading. If startingResources.contains(targetResources), returns 0 rolls and a copy of startingResources with identical amounts.
Throws:
CutoffExceededException - if total number of rolls > cutoff
See Also:
calculateRollsFast(SOCResourceSet, SOCResourceSet, int, boolean[])

calculateRollsAccurate

protected SOCResSetBuildTimePair calculateRollsAccurate(SOCResourceSet startingResources,
                                                        SOCResourceSet targetResources,
                                                        int cutoff,
                                                        boolean[] ports)
                                                 throws CutoffExceededException
this figures out how many rolls it would take this player to get the target set of resources given a starting set

Parameters:
startingResources - the starting resources
targetResources - the target resources
cutoff - throw an exception if the total speed is greater than this
ports - a list of port flags
Returns:
the number of rolls and our resources when the target is reached. If startingResources.contains(targetResources), returns 0 rolls and a null resource set.
Throws:
CutoffExceededException - if estimate more than cutoff turns to obtain targetResources