soc.robot
Class SOCRobotNegotiator

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

public class SOCRobotNegotiator
extends java.lang.Object

Make and consider resource trade offers with other players.

Moved the routines that make and consider offers out of the robot brain.

Author:
Robert S. Thomas

Field Summary
static int ACCEPT_OFFER
           
protected  SOCRobotBrain brain
           
protected  java.util.Stack<SOCPossiblePiece> buildingPlan
          ourPlayerData's building plan.
static int COUNTER_OFFER
           
protected  SOCRobotDM decisionMaker
           
protected  SOCGame game
           
protected  boolean[][] isSellingResource
           
protected  java.util.Vector<SOCTradeOffer> offersMade
           
protected  SOCPlayer ourPlayerData
           
private  int ourPlayerNumber
          ourPlayerData's player number.
protected  SOCPlayerTracker ourPlayerTracker
           
protected  java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers
           
static int REJECT_OFFER
           
protected  int strategyType
           
protected  SOCPossiblePiece[] targetPieces
           
protected  boolean[][] wantsAnotherOffer
           
protected static int WIN_GAME_CUTOFF
           
 
Constructor Summary
SOCRobotNegotiator(SOCRobotBrain br)
          constructor
 
Method Summary
 void addToOffersMade(SOCTradeOffer offer)
          add an offer to the offers made list
 int considerOffer2(SOCTradeOffer offer, int receiverNum)
          consider an offer made by another player
protected  int getETAToTargetResources(SOCPlayer player, SOCResourceSet targetResources, SOCResourceSet giveSet, SOCResourceSet getSet, SOCBuildingSpeedEstimate estimate)
          another aux function this one returns the number of rolls until we reach the target given a possible offer
 SOCTradeOffer getOfferToBank(SOCResourceSet targetResources)
           
 SOCTradeOffer getOfferToBank(SOCResourceSet targetResources, SOCResourceSet ourResources)
           
 SOCTradeOffer makeCounterOffer(SOCTradeOffer originalOffer)
           
 SOCTradeOffer makeOffer(SOCPossiblePiece targetPiece)
          make an offer to another player
protected  SOCTradeOffer makeOfferAux(SOCResourceSet giveResourceSet, SOCResourceSet getResourceSet, int neededResource)
          aux function for make offer
 void markAsNotSelling(int pn, int rsrcType)
          mark a player as not selling a resource
 void markAsNotWantingAnotherOffer(int pn, int rsrcType)
          mark a player as not wanting another offer
 void markAsSelling(int pn, int rsrcType)
          mark a player as willing to sell a resource
 void markAsWantsAnotherOffer(int pn, int rsrcType)
          mark a player as wanting another offer
 void resetIsSelling()
          reset the isSellingResource array so that if the player has the resource, then he is selling it
 void resetOffersMade()
          reset offers made
 void resetTargetPieces()
          reset target pieces for all players
 void resetWantsAnotherOffer()
          reset the wantsAnotherOffer array to all false
 void setTargetPiece(int pn, SOCPossiblePiece piece)
          set a target piece for a player
 boolean wantsAnotherOffer(int pn, int rsrcType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WIN_GAME_CUTOFF

protected static final int WIN_GAME_CUTOFF
See Also:
Constant Field Values

REJECT_OFFER

public static final int REJECT_OFFER
See Also:
Constant Field Values

ACCEPT_OFFER

public static final int ACCEPT_OFFER
See Also:
Constant Field Values

COUNTER_OFFER

public static final int COUNTER_OFFER
See Also:
Constant Field Values

brain

protected SOCRobotBrain brain

strategyType

protected int strategyType

game

protected SOCGame game

buildingPlan

protected java.util.Stack<SOCPossiblePiece> buildingPlan
ourPlayerData's building plan. A stack of SOCPossiblePiece.


playerTrackers

protected java.util.HashMap<java.lang.Integer,SOCPlayerTracker> playerTrackers

ourPlayerTracker

protected SOCPlayerTracker ourPlayerTracker

ourPlayerData

protected final SOCPlayer ourPlayerData

ourPlayerNumber

private final int ourPlayerNumber
ourPlayerData's player number.

Since:
2.0.00

decisionMaker

protected SOCRobotDM decisionMaker

isSellingResource

protected boolean[][] isSellingResource

wantsAnotherOffer

protected boolean[][] wantsAnotherOffer

offersMade

protected java.util.Vector<SOCTradeOffer> offersMade

targetPieces

protected SOCPossiblePiece[] targetPieces
Constructor Detail

SOCRobotNegotiator

public SOCRobotNegotiator(SOCRobotBrain br)
constructor

Parameters:
br - the robot brain
Method Detail

resetTargetPieces

public void resetTargetPieces()
reset target pieces for all players


setTargetPiece

public void setTargetPiece(int pn,
                           SOCPossiblePiece piece)
set a target piece for a player

Parameters:
pn - the player number
piece - the piece that they want to build next

resetOffersMade

public void resetOffersMade()
reset offers made


addToOffersMade

public void addToOffersMade(SOCTradeOffer offer)
add an offer to the offers made list

Parameters:
offer - the offer

resetIsSelling

public void resetIsSelling()
reset the isSellingResource array so that if the player has the resource, then he is selling it


resetWantsAnotherOffer

public void resetWantsAnotherOffer()
reset the wantsAnotherOffer array to all false


markAsNotSelling

public void markAsNotSelling(int pn,
                             int rsrcType)
mark a player as not selling a resource

Parameters:
pn - the number of the player
rsrcType - the type of resource

markAsSelling

public void markAsSelling(int pn,
                          int rsrcType)
mark a player as willing to sell a resource

Parameters:
pn - the number of the player
rsrcType - the type of resource

markAsNotWantingAnotherOffer

public void markAsNotWantingAnotherOffer(int pn,
                                         int rsrcType)
mark a player as not wanting another offer

Parameters:
pn - the number of the player
rsrcType - the type of resource

markAsWantsAnotherOffer

public void markAsWantsAnotherOffer(int pn,
                                    int rsrcType)
mark a player as wanting another offer

Parameters:
pn - the number of the player
rsrcType - the type of resource

wantsAnotherOffer

public boolean wantsAnotherOffer(int pn,
                                 int rsrcType)
Parameters:
pn - the number of the player
rsrcType - the type of resource
Returns:
true if the player is marked as wanting a better offer

makeOffer

public SOCTradeOffer makeOffer(SOCPossiblePiece targetPiece)
make an offer to another player

Parameters:
targetPiece - the piece that we want to build
Returns:
the offer we want to make, or null for no offer

makeOfferAux

protected SOCTradeOffer makeOfferAux(SOCResourceSet giveResourceSet,
                                     SOCResourceSet getResourceSet,
                                     int neededResource)
aux function for make offer


getETAToTargetResources

protected int getETAToTargetResources(SOCPlayer player,
                                      SOCResourceSet targetResources,
                                      SOCResourceSet giveSet,
                                      SOCResourceSet getSet,
                                      SOCBuildingSpeedEstimate estimate)
another aux function this one returns the number of rolls until we reach the target given a possible offer

Parameters:
player - our player data
targetResources - the resources we want
giveSet - the set of resources we're giving
getSet - the set of resources we're receiving
estimate - a SOCBuildingSpeedEstimate for our player

considerOffer2

public int considerOffer2(SOCTradeOffer offer,
                          int receiverNum)
consider an offer made by another player

Parameters:
offer - the offer to consider
receiverNum - the player number of the receiver
Returns:
if we want to accept, reject, or make a counter offer ( ACCEPT_OFFER, REJECT_OFFER, or COUNTER_OFFER )

makeCounterOffer

public SOCTradeOffer makeCounterOffer(SOCTradeOffer originalOffer)
Parameters:
originalOffer - the offer given to us
Returns:
a counter offer or null

getOfferToBank

public SOCTradeOffer getOfferToBank(SOCResourceSet targetResources,
                                    SOCResourceSet ourResources)
Parameters:
targetResources - what resources we want
ourResources - the resources we have
Returns:
the offer that we'll make to the bank/ports, or null if ourResources already contains all needed targetResources

getOfferToBank

public SOCTradeOffer getOfferToBank(SOCResourceSet targetResources)
Parameters:
targetResources - what resources we want
Returns:
the offer that we'll make to the bank/ports based on the resources we have, or null if ourPlayerData.getResources() already contains all needed targetResources