soc.game
Class SOCPlayer

java.lang.Object
  extended bysoc.game.SOCPlayer
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, SOCDevCardConstants, SOCResourceConstants

public class SOCPlayer
extends java.lang.Object
implements SOCResourceConstants, SOCDevCardConstants, java.io.Serializable, java.lang.Cloneable

A class for holding and manipulating player data. The player exists within one SOCGame, not persistent between games like SOCClient.

Author:
Robert S Thomas
See Also:
Serialized Form

Field Summary
private  boolean boardResetAskedThisTurn
          this is true if the player asked to reset the board this turn
private  int buildingVP
          the number of victory points for settlements and cities
private  java.util.Vector cities
          a list of this player's cities in play
private  SOCTradeOffer currentOffer
          this is the current trade offer that this player is making
private  SOCDevCardSet devCards
          how many of each type of development card this player has
private  int faceId
          which face image this player is using
private  int finalTotalVP
          the final total score (pushed from server at end of game), or 0 if no score has been forced.
private  SOCGame game
          the game that this player is in
protected  int lastRoadCoord
          The coordinates of our most recent road
protected  int lastSettlementCoord
          The coordinates of our most recent settlement
private  boolean[] legalRoads
          a list of edges where it is legal to place a road.
private  boolean[] legalSettlements
          a list of nodes where it is legal to place a settlement.
private  int longestRoadLength
          length of the longest road for this player
private  java.util.Vector lrPaths
          list of longest paths
private  java.lang.String name
          the name of the player
private  boolean needToDiscard
          this flag is true if the player needs to discard
private  int numKnights
          how many knights this player has in play
private  int[] numPieces
          the number of pieces not in play
private  SOCPlayerNumbers ourNumbers
          the numbers that our settlements are touching
private  java.util.Vector pieces
          a list of this player's pieces in play
private  boolean playedDevCard
          this is true if the player played a development card this turn
private  int playerNumber
          The integer id for this player (0 to n-1).
private  boolean[] ports
          a boolean array stating wheather this player is touching a particular kind of port
private  boolean[] potentialCities
          a list of nodes where a city could be placed on the next turn.
private  boolean[] potentialRoads
          a list of edges where a road could be placed on the next turn.
private  boolean[] potentialSettlements
          a list of nodes where a settlement could be placed on the next turn.
private  SOCResourceSet resources
          how many of each resource this player has
private  boolean[][] roadNodeGraph
          a graph of what nodes are connected by this player's roads
private  java.util.Vector roadNodes
          all of the nodes that this player's roads touch this is used to calculate longest road
private  java.util.Vector roads
          a list of this player's roads in play
private  boolean robotFlag
          this is true if this player is a robot
private  java.util.Vector settlements
          a list of this player's settlements in play
 
Fields inherited from interface soc.game.SOCResourceConstants
CLAY, MAXPLUSONE, MIN, ORE, SHEEP, UNKNOWN, WHEAT, WOOD
 
Fields inherited from interface soc.game.SOCDevCardConstants
CAP, DISC, KNIGHT, LIB, MAX_KNOWN, MAXPLUSONE, MIN, MONO, ROADS, TEMP, TOW, UNIV, UNKNOWN
 
Constructor Summary
SOCPlayer(int pn, SOCGame ga)
          create a new player
SOCPlayer(SOCPlayer player)
          create a copy of the player
 
Method Summary
 int calcLongestRoad2()
          Calculates the longest road for a player
 void clearPotentialSettlements()
          Set all nodes to not be potential settlements
 SOCPlayer copy()
           
 void destroyPlayer()
          set vars to null so gc can clean up
 void forceFinalVP(int score)
          If game is over, server can push the final score for each player to the client.
 java.util.Vector getCities()
           
 SOCTradeOffer getCurrentOffer()
           
 SOCDevCardSet getDevCards()
           
 int getFaceId()
          get the face image id
 SOCGame getGame()
           
 int getLastRoadCoord()
           
 int getLastSettlementCoord()
           
 int getLongestRoadLength()
           
 java.util.Vector getLRPaths()
           
 java.lang.String getName()
           
 boolean getNeedToDiscard()
           
 SOCPlayerNumbers getNumbers()
           
 int getNumKnights()
           
 int getNumPieces(int ptype)
           
 java.util.Vector getPieces()
           
 int getPlayerNumber()
           
 boolean getPortFlag(int portType)
           
 boolean[] getPortFlags()
           
 int getPublicVP()
          This player's number of publicly known victory points.
 SOCResourceSet getResources()
           
 java.util.Vector getRoadNodes()
           
 java.util.Vector getRoads()
           
 java.util.Vector getSettlements()
           
 int getTotalVP()
           
 boolean hasAskedBoardReset()
           
 boolean hasLargestArmy()
           
 boolean hasLongestRoad()
           
 boolean hasPlayedDevCard()
           
 boolean hasPotentialCity()
           
 boolean hasPotentialRoad()
           
 boolean hasPotentialSettlement()
           
 boolean hasUnplayedDevCards()
           
 void incrementNumKnights()
          increment the number of knights in play
private  void initLegalAndPotentialSettlements()
          initialize the legal settlements array
private  void initLegalRoads()
          initialize the legalRoads array
 boolean isConnectedByRoad(int node1, int node2)
           
 boolean isLegalRoad(int edge)
           
 boolean isPotentialCity(int node)
           
 boolean isPotentialRoad(int edge)
           
 boolean isPotentialSettlement(int node)
           
 boolean isRobot()
           
 void putPiece(SOCPlayingPiece piece)
          put a piece into play note: placing a city automatically removes the settlement there
 void removePiece(SOCPlayingPiece piece)
          remove a player's piece from the board2 and put it back in the player's hand NOTE: Does NOT update the potential building lists for removing settlements or cities.
 void setAskedBoardReset(boolean value)
          set the flag indicating if the player asked to reset the board this turn
 void setCurrentOffer(SOCTradeOffer of)
          set the current offer for this player
 void setFaceId(int id)
          set the face image id
 void setLongestRoadLength(int len)
          set the longest road length
 void setLRPaths(java.util.Vector vec)
          set the longest paths vector
 void setName(java.lang.String na)
          set the name of the player
 void setNeedToDiscard(boolean value)
          set the "need to discard" flag
 void setNumKnights(int nk)
          set the number of knights in play
 void setNumPieces(int ptype, int amt)
          set the amount of pieces not in play for a particular type of piece
 void setPlayedDevCard(boolean value)
          set the playedDevCard flag
 void setPortFlag(int portType, boolean value)
          set a port flag
 void setPotentialSettlements(java.util.Vector psList)
          set which nodes are potential settlements
 void setRobotFlag(boolean value)
          set the robot flag
 void undoPutPiece(SOCPlayingPiece piece)
          undo the putting of a piece
protected  void undoPutPieceAuxSettlement(int settlementNode)
          Auxiliary function for undoing settlement placement
 void updatePotentials(SOCPlayingPiece piece)
          update the arrays that keep track of where this player can play a piece
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name
the name of the player


playerNumber

private int playerNumber
The integer id for this player (0 to n-1).


game

private SOCGame game
the game that this player is in


numPieces

private int[] numPieces
the number of pieces not in play


pieces

private java.util.Vector pieces
a list of this player's pieces in play


roads

private java.util.Vector roads
a list of this player's roads in play


settlements

private java.util.Vector settlements
a list of this player's settlements in play


cities

private java.util.Vector cities
a list of this player's cities in play


lastSettlementCoord

protected int lastSettlementCoord
The coordinates of our most recent settlement


lastRoadCoord

protected int lastRoadCoord
The coordinates of our most recent road


longestRoadLength

private int longestRoadLength
length of the longest road for this player


lrPaths

private java.util.Vector lrPaths
list of longest paths


resources

private SOCResourceSet resources
how many of each resource this player has


devCards

private SOCDevCardSet devCards
how many of each type of development card this player has


numKnights

private int numKnights
how many knights this player has in play


buildingVP

private int buildingVP
the number of victory points for settlements and cities


finalTotalVP

private int finalTotalVP
the final total score (pushed from server at end of game), or 0 if no score has been forced.

See Also:
forceFinalVP(int)

needToDiscard

private boolean needToDiscard
this flag is true if the player needs to discard


roadNodes

private java.util.Vector roadNodes
all of the nodes that this player's roads touch this is used to calculate longest road


roadNodeGraph

private boolean[][] roadNodeGraph
a graph of what nodes are connected by this player's roads


legalRoads

private boolean[] legalRoads
a list of edges where it is legal to place a road. an edge is legal if a road could eventually be placed there.


legalSettlements

private boolean[] legalSettlements
a list of nodes where it is legal to place a settlement. a node is legal if a settlement could eventually be placed there.


potentialRoads

private boolean[] potentialRoads
a list of edges where a road could be placed on the next turn.


potentialSettlements

private boolean[] potentialSettlements
a list of nodes where a settlement could be placed on the next turn.


potentialCities

private boolean[] potentialCities
a list of nodes where a city could be placed on the next turn.


ports

private boolean[] ports
a boolean array stating wheather this player is touching a particular kind of port


currentOffer

private SOCTradeOffer currentOffer
this is the current trade offer that this player is making


playedDevCard

private boolean playedDevCard
this is true if the player played a development card this turn


boardResetAskedThisTurn

private boolean boardResetAskedThisTurn
this is true if the player asked to reset the board this turn


robotFlag

private boolean robotFlag
this is true if this player is a robot


faceId

private int faceId
which face image this player is using


ourNumbers

private SOCPlayerNumbers ourNumbers
the numbers that our settlements are touching

Constructor Detail

SOCPlayer

public SOCPlayer(SOCPlayer player)
create a copy of the player

Parameters:
player - the player to copy

SOCPlayer

public SOCPlayer(int pn,
                 SOCGame ga)
create a new player

Parameters:
pn - the player number
ga - the game that the player is in
Method Detail

initLegalRoads

private final void initLegalRoads()
initialize the legalRoads array


initLegalAndPotentialSettlements

private final void initLegalAndPotentialSettlements()
initialize the legal settlements array


clearPotentialSettlements

public void clearPotentialSettlements()
Set all nodes to not be potential settlements


setName

public void setName(java.lang.String na)
set the name of the player

Parameters:
na - the name

getName

public java.lang.String getName()
Returns:
the name of the player

getPlayerNumber

public int getPlayerNumber()
Returns:
the player id

getGame

public SOCGame getGame()
Returns:
the game that this player is in

hasPlayedDevCard

public boolean hasPlayedDevCard()
Returns:
true if the player played a dev card this turn

setPlayedDevCard

public void setPlayedDevCard(boolean value)
set the playedDevCard flag

Parameters:
value - the value of the flag

hasAskedBoardReset

public boolean hasAskedBoardReset()
Returns:
true if the player asked to reset the board this turn

setAskedBoardReset

public void setAskedBoardReset(boolean value)
set the flag indicating if the player asked to reset the board this turn

Parameters:
value - true to set, false to clear

setNeedToDiscard

public void setNeedToDiscard(boolean value)
set the "need to discard" flag

Parameters:
value - the value of the flag

getNeedToDiscard

public boolean getNeedToDiscard()
Returns:
true if this player needs to discard

setRobotFlag

public void setRobotFlag(boolean value)
set the robot flag

Parameters:
value -

isRobot

public boolean isRobot()
Returns:
the value of the robot flag

setFaceId

public void setFaceId(int id)
set the face image id

Parameters:
id - the image id

getFaceId

public int getFaceId()
get the face image id


getNumbers

public SOCPlayerNumbers getNumbers()
Returns:
the numbers that this player's settlements are touching

getNumPieces

public int getNumPieces(int ptype)
Parameters:
ptype - the type of piece
Returns:
the number of pieces not in play for a particualr type of piece

setNumPieces

public void setNumPieces(int ptype,
                         int amt)
set the amount of pieces not in play for a particular type of piece

Parameters:
ptype - the type of piece
amt - the amount

getPieces

public java.util.Vector getPieces()
Returns:
the list of pieces in play

getRoads

public java.util.Vector getRoads()
Returns:
the list of roads in play

getSettlements

public java.util.Vector getSettlements()
Returns:
the list of settlements in play

getCities

public java.util.Vector getCities()
Returns:
the list of cities in play

getLastSettlementCoord

public int getLastSettlementCoord()
Returns:
the coordinates of the last settlement played by this player

getLastRoadCoord

public int getLastRoadCoord()
Returns:
the coordinates of the last road played by this player

getLongestRoadLength

public int getLongestRoadLength()
Returns:
the longest road length

getLRPaths

public java.util.Vector getLRPaths()
Returns:
longest road paths

setLRPaths

public void setLRPaths(java.util.Vector vec)
set the longest paths vector

Parameters:
vec - the vector

setLongestRoadLength

public void setLongestRoadLength(int len)
set the longest road length

Parameters:
len - the length

getResources

public SOCResourceSet getResources()
Returns:
the resource set

getDevCards

public SOCDevCardSet getDevCards()
Returns:
the development card set

hasUnplayedDevCards

public boolean hasUnplayedDevCards()
Returns:
whether this player has any unplayed dev cards
See Also:
getDevCards()

getNumKnights

public int getNumKnights()
Returns:
the number of knights in play

setNumKnights

public void setNumKnights(int nk)
set the number of knights in play

Parameters:
nk - the number of knights

incrementNumKnights

public void incrementNumKnights()
increment the number of knights in play


hasLongestRoad

public boolean hasLongestRoad()
Returns:
true if this player has the longest road

hasLargestArmy

public boolean hasLargestArmy()
Returns:
true if this player has the largest army

getPublicVP

public int getPublicVP()
This player's number of publicly known victory points. Public victory points exclude VP development cards, except at end of game, when they've been announced by server.

Returns:
the number of publicly known victory points
See Also:
forceFinalVP(int)

getTotalVP

public int getTotalVP()
Returns:
the actual number of victory points (including VP cards)
See Also:
forceFinalVP(int)

forceFinalVP

public void forceFinalVP(int score)
If game is over, server can push the final score for each player to the client. During play, true scores aren't known, because of hidden victory-point cards. getTotalVP() and getPublicVP() will report this, if set.

Parameters:
score - Total score for the player, or 0 for no forced total.

getRoadNodes

public java.util.Vector getRoadNodes()
Returns:
the list of nodes that touch the roads in play

getCurrentOffer

public SOCTradeOffer getCurrentOffer()
Returns:
this player's latest offer

setCurrentOffer

public void setCurrentOffer(SOCTradeOffer of)
set the current offer for this player

Parameters:
of - the offer

isConnectedByRoad

public boolean isConnectedByRoad(int node1,
                                 int node2)
Parameters:
node1 - coordinates of first node
node2 - coordinates of second node
Returns:
true if one of this player's roads connects the two nodes.

putPiece

public void putPiece(SOCPlayingPiece piece)
put a piece into play note: placing a city automatically removes the settlement there

Parameters:
piece - the piece to be put into play

undoPutPiece

public void undoPutPiece(SOCPlayingPiece piece)
undo the putting of a piece

Parameters:
piece - the piece to be put into play For removing second initial settlement (state START2B), will zero the player's resource cards.

undoPutPieceAuxSettlement

protected void undoPutPieceAuxSettlement(int settlementNode)
Auxiliary function for undoing settlement placement

Parameters:
settlementNode - the node we want to consider

removePiece

public void removePiece(SOCPlayingPiece piece)
remove a player's piece from the board2 and put it back in the player's hand NOTE: Does NOT update the potential building lists for removing settlements or cities. DOES update potential road lists.


updatePotentials

public void updatePotentials(SOCPlayingPiece piece)
update the arrays that keep track of where this player can play a piece

Parameters:
piece - a piece that has just been played

setPotentialSettlements

public void setPotentialSettlements(java.util.Vector psList)
set which nodes are potential settlements

Parameters:
psList - the list of potential settlements

isPotentialSettlement

public boolean isPotentialSettlement(int node)
Parameters:
node - the coordinates of a node on the board
Returns:
true if this node is a potential settlement

isPotentialCity

public boolean isPotentialCity(int node)
Parameters:
node - the coordinates of a node on the board
Returns:
true if this node is a potential city

isPotentialRoad

public boolean isPotentialRoad(int edge)
Parameters:
edge - the coordinates of an edge on the board
Returns:
true if this edge is a potential road

isLegalRoad

public boolean isLegalRoad(int edge)
Parameters:
edge - the coordinates of an edge on the board
Returns:
true if this edge is a legal road

hasPotentialRoad

public boolean hasPotentialRoad()
Returns:
true if there is at least one potential road

hasPotentialSettlement

public boolean hasPotentialSettlement()
Returns:
true if there is at least one potential settlement

hasPotentialCity

public boolean hasPotentialCity()
Returns:
true if there is at least one potential city

calcLongestRoad2

public int calcLongestRoad2()
Calculates the longest road for a player

Returns:
the length of the longest road for that player

setPortFlag

public void setPortFlag(int portType,
                        boolean value)
set a port flag

Parameters:
portType - the type of port, see SOCBoard
value - true or false

getPortFlag

public boolean getPortFlag(int portType)
Parameters:
portType - the type of port, see SOCBoard
Returns:
the port flag for a type of port

getPortFlags

public boolean[] getPortFlags()
Returns:
the ports array

copy

public SOCPlayer copy()
Returns:
a copy of this player

destroyPlayer

public void destroyPlayer()
set vars to null so gc can clean up