JSettlers v1.0.6 API
Built ${date}

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

Author:
Robert S Thomas
See Also:
Serialized Form

Field Summary
protected  int lastRoadCoord
          The coordinates of our most recent road
protected  int lastSettlementCoord
          The coordinates of our most recent settlement
 
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, 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
 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()
           
 SOCResourceSet getResources()
           
 java.util.Vector getRoadNodes()
           
 java.util.Vector getRoads()
           
 java.util.Vector getSettlements()
           
 int getTotalVP()
           
 boolean hasLargestArmy()
           
 boolean hasLongestRoad()
           
 boolean hasPlayedDevCard()
           
 boolean hasPotentialCity()
           
 boolean hasPotentialRoad()
           
 boolean hasPotentialSettlement()
           
 void incrementNumKnights()
          increment the number of knights in play
 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 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

lastSettlementCoord

protected int lastSettlementCoord
The coordinates of our most recent settlement


lastRoadCoord

protected int lastRoadCoord
The coordinates of our most recent road

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

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

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

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()
Returns:
the number of publicly known victory points

getTotalVP

public int getTotalVP()
Returns:
the actual number of victory points

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

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


JSettlers v1.0.6 API
Built ${date}