soc.robot
Class OpeningBuildStrategy

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

public class OpeningBuildStrategy
extends java.lang.Object

This class is a temporary class put in place to slowly pull tasks out of SOCRobotBrain and start replacing them with classes that implement strategy interfaces. (Strategy Pattern)

Author:
Eli McGowan

Field Summary
protected  int firstSettlement
          used in planning where to put our first and second settlements
private  SOCGame game
          Our game
private  D log
          debug logging
private  SOCPlayer ourPlayerData
          Our SOCRobotBrain's player
private  int plannedRoadDestinationNode
          Coordinate of a future settlement 2 nodes away from settlementNode (from firstSettlement or secondSettlement).
protected  int[] resourceEstimates
          Cached resource estimates for the board; resourceEstimates[SOCBoard.CLAY_HEX] == the clay rarity, as an integer percentage 0-100 of dice rolls.
protected  int secondSettlement
          used in planning where to put our first and second settlements
 
Constructor Summary
OpeningBuildStrategy(SOCGame ga, SOCPlayer pl)
          Create an OpeningBuildStrategy for a SOCRobotBrain's player.
 
Method Summary
protected  void bestSpot2AwayFromANodeSet(SOCBoard board, java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodesIn, java.util.Vector<java.lang.Integer> nodeSet, int weight)
          Takes a table of nodes and adds a weighted score to each node score in the table.
protected  void bestSpotForNumbers(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodes, SOCPlayer player, int weight)
          Takes a table of nodes and adds a weighted score to each node score in the table.
protected  void bestSpotInANodeSet(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodesIn, java.util.Vector<java.lang.Integer> nodeSet, int weight)
          Takes a table of nodes and adds a weighted score to each node score in the table.
 int[] estimateResourceRarity()
          Estimate the rarity of each resource, given this board's resource locations vs dice numbers.
 int getPlannedInitRoadDestinationNode()
          Get the node coordinate of a future settlement 2 nodes away from our most recent settlement node.
protected  int numberOfEnemyBuilds()
          Calculate the number of builds before our next turn during init placement.
 int planInitialSettlements()
          figure out where to place the two settlements
 int planInitRoad()
          Plan and place a road attached to our most recently placed initial settlement, in game states START1B, START2B, START3B.
 int planSecondSettlement()
          figure out where to place the second settlement
protected  void scoreNodesForSettlements(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodes, int numberWeight, int miscPortWeight, int portWeight)
          Given a set of nodes, run a bunch of metrics across them to find which one is best for building a settlement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

game

private final SOCGame game
Our game


ourPlayerData

private final SOCPlayer ourPlayerData
Our SOCRobotBrain's player


log

private transient D log
debug logging


firstSettlement

protected int firstSettlement
used in planning where to put our first and second settlements


secondSettlement

protected int secondSettlement
used in planning where to put our first and second settlements


plannedRoadDestinationNode

private int plannedRoadDestinationNode
Coordinate of a future settlement 2 nodes away from settlementNode (from firstSettlement or secondSettlement). Valid after calling planInitRoad().

Since:
2.0.00

resourceEstimates

protected int[] resourceEstimates
Cached resource estimates for the board; resourceEstimates[SOCBoard.CLAY_HEX] == the clay rarity, as an integer percentage 0-100 of dice rolls. Initialized in estimateResourceRarity().

Constructor Detail

OpeningBuildStrategy

OpeningBuildStrategy(SOCGame ga,
                     SOCPlayer pl)
Create an OpeningBuildStrategy for a SOCRobotBrain's player.

Parameters:
ga - Our game
pl - Our player data in ga
Method Detail

getPlannedInitRoadDestinationNode

public int getPlannedInitRoadDestinationNode()
Get the node coordinate of a future settlement 2 nodes away from our most recent settlement node. Valid after calling planInitRoad().

Since:
2.0.00

planInitialSettlements

public int planInitialSettlements()
figure out where to place the two settlements

Returns:
firstSettlement, or 0 if no potential settlements for our player

planSecondSettlement

public int planSecondSettlement()
figure out where to place the second settlement

Returns:
secondSettlement, or -1 if none

planInitRoad

public int planInitRoad()
Plan and place a road attached to our most recently placed initial settlement, in game states START1B, START2B, START3B. Also sets getPlannedInitRoadDestinationNode().

Road choice is based on the best nearby potential settlements, and doesn't directly check ourPlayerData.isPotentialRoad(edgeCoord). If the server rejects our road choice, then SOCRobotBrain.cancelWrongPiecePlacementLocal(SOCPlayingPiece) will need to know which settlement node we were aiming for, and call ourPlayerData.clearPotentialSettlement(nodeCoord). The SOCRobotBrain.lastStartingRoadTowardsNode field holds this coordinate.

Returns:
road edge adjacent to initial settlement node

scoreNodesForSettlements

protected void scoreNodesForSettlements(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodes,
                                        int numberWeight,
                                        int miscPortWeight,
                                        int portWeight)
Given a set of nodes, run a bunch of metrics across them to find which one is best for building a settlement.

Parameters:
nodes - a hashtable of nodes; the scores in the table will be modified. Key = coord Integer; value = score Integer.
numberWeight - the weight given to nodes on good numbers
miscPortWeight - the weight given to nodes on 3:1 ports
portWeight - the weight given to nodes on good 2:1 ports

bestSpotInANodeSet

protected void bestSpotInANodeSet(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodesIn,
                                  java.util.Vector<java.lang.Integer> nodeSet,
                                  int weight)
Takes a table of nodes and adds a weighted score to each node score in the table. A vector of nodes that we want to be on is also taken as an argument. Here are the rules for scoring: If a node is in the desired set of nodes it gets 100. Otherwise it gets 0.

Parameters:
nodesIn - the table of nodes to evaluate: Hashtable<Integer,Integer> . Contents will be modified by the scoring.
nodeSet - the set of desired nodes
weight - the score multiplier

bestSpot2AwayFromANodeSet

protected void bestSpot2AwayFromANodeSet(SOCBoard board,
                                         java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodesIn,
                                         java.util.Vector<java.lang.Integer> nodeSet,
                                         int weight)
Takes a table of nodes and adds a weighted score to each node score in the table. A vector of nodes that we want to be near is also taken as an argument. Here are the rules for scoring: If a node is two away from a node in the desired set of nodes it gets 100. Otherwise it gets 0.

Parameters:
board - the game board
nodesIn - the table of nodes to evaluate: Hashtable<Integer,Integer> . Contents will be modified by the scoring.
nodeSet - the set of desired nodes
weight - the score multiplier

estimateResourceRarity

public int[] estimateResourceRarity()
Estimate the rarity of each resource, given this board's resource locations vs dice numbers. Useful for initial settlement placement and free-resource choice (when no other info available). This is based on the board and doesn't change when pieces are placed. Cached after the first call, as resourceEstimates.

Calls each hex's SOCBoard.getHexTypeFromCoord(int), ignores all hex types besides the usual SOCBoard.CLAY_HEX through SOCBoard.WOOD_HEX and SOCBoardLarge.GOLD_HEX.

Returns:
an array of rarity numbers, where estimates[SOCBoard.CLAY_HEX] == the clay rarity, as an integer percentage 0-100 of dice rolls.

numberOfEnemyBuilds

protected int numberOfEnemyBuilds()
Calculate the number of builds before our next turn during init placement.


bestSpotForNumbers

protected void bestSpotForNumbers(java.util.Hashtable<java.lang.Integer,java.lang.Integer> nodes,
                                  SOCPlayer player,
                                  int weight)
Takes a table of nodes and adds a weighted score to each node score in the table. Nodes touching hexes with better numbers get better scores. Also numbers that the player isn't touching yet are better than ones that the player is already touching.

Parameters:
nodes - the table of nodes with scores: Hashtable<Integer,Integer> . Contents will be modified by the scoring.
player - the player that we are doing the rating for, or null; will give a bonus to numbers the player isn't already touching
weight - a number that is multiplied by the score