soc.robot
Class SOCPossiblePiece

java.lang.Object
  extended by soc.robot.SOCPossiblePiece
Direct Known Subclasses:
SOCPossibleCard, SOCPossibleCity, SOCPossiblePickSpecialItem, SOCPossibleRoad, SOCPossibleSettlement

public abstract class SOCPossiblePiece
extends java.lang.Object

Pieces that a player might build, or action (buy card) a player might take. Used by SOCRobotDM for tracking and planning moves.

Also tracks threats (opponents' possible pieces) to each of our player's possible pieces. Examples of threats are opponent roads on the same edge as this road, settlements or cities that split a road, etc.

Although it's not a board piece type, SOCPossibleCard is a type here because the player could buy them as part of a building plan.

Author:
Robert S. Thomas

Field Summary
protected  java.util.Vector<SOCPossiblePiece> biggestThreats
          this is the piece that we need to beat to build this one
static int CARD
          Type constant for a possible card.
static int CITY
          Type constant for a possible city.
protected  int coord
          Where this piece is on the board.
protected  int eta
          this is how soon we estimate we can build this piece measured in turns (ETA)
protected  boolean hasBeenExpanded
          this flag is used for expansion
static int MAXPLUSONE
           
static int MIN
          MIN is -3 for PICK_SPECIAL, but nothing currently uses -1.
static int PICK_SPECIAL
          Type constant for SOCSetSpecialItem.OP_PICK requests, subclass SOCPossiblePickSpecialItem.
protected  int pieceType
          The type of this playing piece; a constant such as ROAD, CITY, etc.
protected  SOCPlayer player
          The player who owns this piece
static int ROAD
          Type constant for a possible road.
protected  float score
          this is a score used for deciding what to build next
static int SETTLEMENT
          Type constant for a possible settlement.
static int SHIP
          Ship, for large sea board.
protected  java.util.Vector<SOCPossiblePiece> threats
          pieces that threaten this piece
protected  boolean threatUpdatedFlag
          this flag is used for threat updating
protected  boolean updated
          this is a flag used for updating
 
Constructor Summary
protected SOCPossiblePiece(int pt, SOCPlayer pl, int coord)
          Construct a SOCPossiblePiece.
 
Method Summary
 void addBiggestThreat(SOCPossiblePiece bt)
          set the biggest threat
 void addThreat(SOCPossiblePiece piece)
          add a threat to the list, if not already there
 void addToScore(float amt)
          add to score, from SOCRobotDM.getETABonus(int, int, float)
 void clearBiggestThreats()
          reset the biggest threat
 void clearThreats()
          clear the list of threats
 void clearUpdateFlag()
          clear the update flag
 java.util.Vector<SOCPossiblePiece> getBiggestThreats()
           
 int getCoordinates()
          Get this piece's coordinates on the board, if any.
 int getETA()
           
 SOCPlayer getPlayer()
           
 SOCResourceSet getResourcesToBuild()
          Based on piece type (getType()), the resources a player needs to build or buy this possible piece.
 float getScore()
           
 java.util.Vector<SOCPossiblePiece> getThreats()
          Get the list of opponents' possible pieces that threaten this possible piece.
 int getType()
           
 boolean hasBeenExpanded()
           
 boolean isETAUpdated()
           
 boolean isThreatUpdated()
           
 void resetExpandedFlag()
          set hasBeenExpanded to false
 void resetScore()
          reset the score
 void setETA(int e)
          update the ETA for this piece
 void setExpandedFlag()
          set hasBeenExpanded to true
 void subtractFromScore(float amt)
          subtract from score
 void threatUpdated()
          mark this piece as having been threat updated
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROAD

public static final int ROAD
Type constant for a possible road. Same value as SOCPlayingPiece.ROAD.

See Also:
Constant Field Values

SETTLEMENT

public static final int SETTLEMENT
Type constant for a possible settlement. Same value as SOCPlayingPiece.SETTLEMENT.

See Also:
Constant Field Values

CITY

public static final int CITY
Type constant for a possible city. Same value as SOCPlayingPiece.CITY.

See Also:
Constant Field Values

SHIP

public static final int SHIP
Ship, for large sea board. Same value as SOCPlayingPiece.SHIP.

Since:
2.0.00
See Also:
Constant Field Values

CARD

public static final int CARD
Type constant for a possible card. getCoordinates() field is not used. CARD is -2, was 4 before v2.0.00.

See Also:
Constant Field Values

PICK_SPECIAL

public static final int PICK_SPECIAL
Type constant for SOCSetSpecialItem.OP_PICK requests, subclass SOCPossiblePickSpecialItem. getCoordinates() field is not used.

Since:
2.0.00
See Also:
Constant Field Values

MIN

public static final int MIN
MIN is -3 for PICK_SPECIAL, but nothing currently uses -1. ROAD is 0.

See Also:
Constant Field Values

MAXPLUSONE

public static final int MAXPLUSONE
See Also:
Constant Field Values

pieceType

protected int pieceType
The type of this playing piece; a constant such as ROAD, CITY, etc. The constant types are the same as in SOCPlayingPiece.getResourcesToBuild(int).


player

protected SOCPlayer player
The player who owns this piece


coord

protected int coord
Where this piece is on the board. Some piece types such as CARD do not use this field, it will be 0 if unused. In some board layouts 0 is a valid coordinate; check the piece type to determine if unused.


eta

protected int eta
this is how soon we estimate we can build this piece measured in turns (ETA)


updated

protected boolean updated
this is a flag used for updating


score

protected float score
this is a score used for deciding what to build next


biggestThreats

protected java.util.Vector<SOCPossiblePiece> biggestThreats
this is the piece that we need to beat to build this one


threats

protected java.util.Vector<SOCPossiblePiece> threats
pieces that threaten this piece


threatUpdatedFlag

protected boolean threatUpdatedFlag
this flag is used for threat updating


hasBeenExpanded

protected boolean hasBeenExpanded
this flag is used for expansion

Constructor Detail

SOCPossiblePiece

protected SOCPossiblePiece(int pt,
                           SOCPlayer pl,
                           int coord)
Construct a SOCPossiblePiece.

Parameters:
pt - Piece type: ROAD, CARD, etc. The type constants are the same as in SOCPlayingPiece.getResourcesToBuild(int).
pl - The owner of this piece
coord - The coordinates for this piece, if any. Some piece types such as CARD do not use this field, they call with coord == 0.
Since:
2.0.00
Method Detail

getType

public int getType()
Returns:
the type of piece; a constant such as ROAD, CITY, etc. The type constants are the same as in SOCPlayingPiece.getResourcesToBuild(int).
See Also:
getResourcesToBuild()

getPlayer

public SOCPlayer getPlayer()
Returns:
the owner of this piece

getCoordinates

public int getCoordinates()
Get this piece's coordinates on the board, if any. Some piece types such as CARD do not use this field.

Returns:
the coordinates for this piece, or 0 if unused. In some board layouts 0 is a valid coordinate; check the piece type to determine if unused.

getETA

public int getETA()
Returns:
the ETA for this piece

setETA

public void setETA(int e)
update the ETA for this piece

Parameters:
e - the new ETA

isETAUpdated

public boolean isETAUpdated()
Returns:
the value of the ETA update flag

clearUpdateFlag

public void clearUpdateFlag()
clear the update flag


resetScore

public void resetScore()
reset the score


addToScore

public void addToScore(float amt)
add to score, from SOCRobotDM.getETABonus(int, int, float)

Parameters:
amt - the amount to add

subtractFromScore

public void subtractFromScore(float amt)
subtract from score

Parameters:
amt - the amount to subtract

getScore

public float getScore()
Returns:
the ETA bonus score
See Also:
SOCRobotDM.getETABonus(int, int, float)

clearBiggestThreats

public void clearBiggestThreats()
reset the biggest threat


addBiggestThreat

public void addBiggestThreat(SOCPossiblePiece bt)
set the biggest threat

Parameters:
bt - the threat

getBiggestThreats

public java.util.Vector<SOCPossiblePiece> getBiggestThreats()
Returns:
the biggest threat

getThreats

public java.util.Vector<SOCPossiblePiece> getThreats()
Get the list of opponents' possible pieces that threaten this possible piece.

Returns:
the list of threats

addThreat

public void addThreat(SOCPossiblePiece piece)
add a threat to the list, if not already there

Parameters:
piece - Opponent's possible piece to add to this possible piece's threat list

isThreatUpdated

public boolean isThreatUpdated()
Returns:
the status of the threatUpdatedFlag

clearThreats

public void clearThreats()
clear the list of threats


threatUpdated

public void threatUpdated()
mark this piece as having been threat updated


hasBeenExpanded

public boolean hasBeenExpanded()
Returns:
the status of the hasBeenExpanded flag

resetExpandedFlag

public void resetExpandedFlag()
set hasBeenExpanded to false


setExpandedFlag

public void setExpandedFlag()
set hasBeenExpanded to true


getResourcesToBuild

public SOCResourceSet getResourcesToBuild()
Based on piece type (getType()), the resources a player needs to build or buy this possible piece.

Unlike SOCPlayingPiece.getResourcesToBuild(int), this method handles non-piece types which the bot may plan to build, such as PICK_SPECIAL.

Returns:
Set of resources, or null if no cost or if piece type unknown
Since:
2.0.00

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a human readable form of this object