|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.game.SOCPlayerNumbers
public class SOCPlayerNumbers
This class tracks what dice-roll numbers a player's pieces are touching, and the probability of getting resources based on their hex types.
Calls each touched hex's SOCBoard.getHexTypeFromCoord(int)
, ignores all hex types besides
the usual SOCBoard.CLAY_HEX
through SOCBoard.WOOD_HEX
and SOCBoardLarge.GOLD_HEX
.
Field Summary | |
---|---|
boolean |
hasSeaBoard
Is this game played on the SOCBoardLarge large board / sea board?
If true, the board's SOCBoard.getBoardEncodingFormat()
must be SOCBoard.BOARD_ENCODING_LARGE . |
private int[] |
landHexCoords
Reference to either SOCBoard.HEXCOORDS_LAND_V1 or SOCBoard.HEXCOORDS_LAND_V2 . |
private java.util.Hashtable<java.lang.Integer,java.util.Vector<IntPair>> |
numberAndResourceForHex
Hex dice-roll resource information, by land-hex coordinate ID. |
private java.util.Vector<java.lang.Integer>[] |
numbersForResource
Dice roll numbers which yield this resource. |
private java.util.Vector<java.lang.Integer>[] |
resourcesForNumber
Resources on dice roll numbers; uses indexes 2-12. |
Constructor Summary | |
---|---|
SOCPlayerNumbers(SOCBoard board)
the constructor for a player's dice-resource numbers. |
|
SOCPlayerNumbers(SOCPlayerNumbers numbers)
make a copy of the player numbers |
Method Summary | |
---|---|
void |
addNumberForResource(int diceNum,
int resource,
int hex)
add a number to the list of dice numbers for a resource |
void |
clear()
clear all of the data |
java.util.Vector<IntPair> |
getNumberResourcePairsForHex(int hexCoord)
|
java.util.Vector<java.lang.Integer> |
getNumbersForResource(int resource)
Get the numbers for a resource type. |
java.util.Vector<java.lang.Integer> |
getNumbersForResource(int resource,
int robberHex)
Get the numbers for a resource type. |
java.util.Vector<java.lang.Integer> |
getResourcesForNumber(int diceNum)
Get this player's resources gained when a dice number is rolled. |
java.util.Vector<java.lang.Integer> |
getResourcesForNumber(int diceNum,
int robberHex)
Get this player's resources gained when a dice number is rolled. |
boolean |
hasNoResourcesForHex(int hexCoord)
Do we receive no resources at all from this hex on any dice rolls? |
boolean |
hasNumber(int number)
return true if this player is touching the requested number |
void |
setLandHexCoordinates(int[] landHex)
Set the land hex coordinates, once the board layout is known. |
java.lang.String |
toString()
return a human readable form of this object |
void |
undoAddNumberForResource(int number,
int resource,
int hex)
remove a number for a resource do this when you take back a piece |
void |
undoUpdateNumbers(int coord,
SOCBoard board)
undo the updating of the numbers data given a node coordinate and a board, remove numbers for this player from the list |
void |
undoUpdateNumbers(SOCPlayingPiece piece,
SOCBoard board)
undo the updating of the numbers data given a piece and a board, remove numbers for this player from the list |
void |
updateNumbers(int nodeCoord,
SOCBoard board)
update the numbers data, based on placing a settlement or upgrading to a city at a node. |
void |
updateNumbers(SOCPlayingPiece piece,
SOCBoard board)
Update the numbers data, based on placing a settlement or upgrading to a city at a node. |
int |
updateNumbersAndProbability(int nodeCoord,
SOCBoard board,
int[] numProb,
java.lang.StringBuffer sb)
Update the numbers data, based on placing a settlement or upgrading to a city at a node, and total the probability for those dice numbers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.util.Vector<java.lang.Integer>[] numbersForResource
SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
.
Each element contains Integer
s for the dice numbers.
SOCBoardLarge.GOLD_HEX
is handled by adding the dice number to
all resource types in addNumberForResource(int, int, int)
.
private java.util.Vector<java.lang.Integer>[] resourcesForNumber
Integer
s for the resource(s),
in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
.
If the number yields more than one of that resource type
(a city, or multiple pieces on the hex), there will be
more than one Integer here with that resource type.
SOCBoardLarge.GOLD_HEX
is handled by adding all resource types to
the dice number in addNumberForResource(int, int, int)
.
private java.util.Hashtable<java.lang.Integer,java.util.Vector<IntPair>> numberAndResourceForHex
IntPair
(diceNum, resource).
If hasSeaBoard
, the resource type may be SOCBoardLarge.GOLD_HEX
.
Until addNumberForResource(int, int, int)
or
updateNumbers(int, SOCBoard)
is called,
any land hex's entry in this hashtable may be null.
private int[] landHexCoords
SOCBoard.HEXCOORDS_LAND_V1
or SOCBoard.HEXCOORDS_LAND_V2
.
Hex coordinates for each land hex on the board, via SOCBoard.getLandHexCoords()
.
In SOCBoard.BOARD_ENCODING_LARGE
, if the game hasn't yet called
SOCBoard.makeNewBoard(Map)
, this may be null
.
public final boolean hasSeaBoard
SOCBoardLarge
large board / sea board?
If true, the board's SOCBoard.getBoardEncodingFormat()
must be SOCBoard.BOARD_ENCODING_LARGE
.
When hasSeaBoard, SOCBoardLarge.GOLD_HEX
is tracked.
When false, it's ignored because the same numeric value in the previous
encoding formats is water (SOCBoard.MISC_PORT_HEX
).
Constructor Detail |
---|
public SOCPlayerNumbers(SOCPlayerNumbers numbers)
numbers
- the player numbers to copypublic SOCPlayerNumbers(SOCBoard board) throws java.lang.IllegalArgumentException
If using SOCBoard.BOARD_ENCODING_LARGE
, and this is the start of
a game that hasn't yet created the layout: The land hex coordinates
will need to be updated later when the board layout is created and sent;
call setLandHexCoordinates(int[])
at that time.
board
- The game board; used only for
SOCBoard.getBoardEncodingFormat()
and SOCBoard.getLandHexCoords()
.
java.lang.IllegalArgumentException
- If boardEncodingFormat value is unknown to this classMethod Detail |
---|
public void clear()
public void setLandHexCoordinates(int[] landHex)
landHex
- Array of hex coordinates for all land hexespublic void updateNumbers(SOCPlayingPiece piece, SOCBoard board)
Given a piece and a board, add numbers for this player to the list:
Calls addNumberForResource(int, int, int)
for each dice number and resource
on the piece node's adjacent hexes.
piece
- the playing piece, used only for its node coordinateboard
- the game boardpublic void updateNumbers(int nodeCoord, SOCBoard board)
Given a node coordinate and a board, add numbers for this player to the list:
Calls addNumberForResource(int, int, int)
for each dice number and resource
on the node's adjacent hexes.
nodeCoord
- the node coordinateboard
- the game boardupdateNumbersAndProbability(int, SOCBoard, int[], StringBuffer)
public int updateNumbersAndProbability(int nodeCoord, SOCBoard board, int[] numProb, java.lang.StringBuffer sb)
Given a node coordinate and a board, add numbers for this player to the list:
Calls addNumberForResource(int, int, int)
for each dice number and resource
on the node's adjacent hexes.
Hexes are ignored if their SOCBoard.getNumberOnHexFromCoord(int)
< 1.
nodeCoord
- the settlement or city's node coordinateboard
- the game boardnumProb
- probability factor for each dice number,
as integers between 0 and 100 (percentage).
numProb[i] is the percentage chance of rolling i.sb
- if not null, a StringBuffer to append each adjacent dice number into for debugging
updateNumbers(int, SOCBoard)
public java.util.Vector<java.lang.Integer> getResourcesForNumber(int diceNum)
SOCBoardLarge.GOLD_HEX
is handled by adding all resource types
to the dice number, if hasSeaBoard
.
So, gold hex numbers will have 5 resources in the Vector
(10 for cities on gold).
diceNum
- the dice number, 2-12
Integer
s for the resource(s),
in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
.
If the number yields more than one of that resource type
(a city, or multiple pieces on the hex), there will be
more than one Integer here with that resource type.getResourcesForNumber(int, int)
public java.util.Vector<java.lang.Integer> getNumbersForResource(int resource)
SOCBoardLarge.GOLD_HEX
is handled by adding the dice number to
all resource types, if hasSeaBoard
.
resource
- the resource, in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
Integer
sgetNumbersForResource(int, int)
public java.util.Vector<IntPair> getNumberResourcePairsForHex(int hexCoord)
hexCoord
- the hex coord
IntPair
(diceNum, resource).
May be null if hexCoord has no resources for us, or is not a valid land hex.
If the number yields more than one of that resource type
(a city, or multiple pieces on the hex), there will be
more than one Integer here with that resource type.
If hasSeaBoard
, a resource type may be SOCBoardLarge.GOLD_HEX
.hasNoResourcesForHex(int)
public boolean hasNoResourcesForHex(int hexCoord)
hexCoord
- the hex coordinate
getNumberResourcePairsForHex(int)
is empty;
False if we do receive resources from this hexpublic java.util.Vector<java.lang.Integer> getNumbersForResource(int resource, int robberHex)
SOCBoardLarge.GOLD_HEX
is handled by adding the dice number to
all resource types, if hasSeaBoard
.
resource
- the resource, in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
robberHex
- the robber hex
Integer
s), taking the robber into account;
if this resource is on two 8s (for example), there will be two Integer
(8) in the
returned vector.getNumbersForResource(int)
public java.util.Vector<java.lang.Integer> getResourcesForNumber(int diceNum, int robberHex)
SOCBoardLarge.GOLD_HEX
is handled by adding all resource types
to the dice number, if hasSeaBoard
.
So, gold hex numbers will have 5 resources in the Vector
(10 for cities on gold).
diceNum
- the dice roll, 2 - 12robberHex
- the robber hex coordinate
SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
.
If the number yields more than one of that resource type
(a city, or multiple pieces on the hex), there will be
more than one Integer here with that resource type.getResourcesForNumber(int)
public void addNumberForResource(int diceNum, int resource, int hex)
diceNum
- the dice-roll numberresource
- the resource, in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
;
resources outside this range are ignored.
If hasSeaBoard
, can be SOCBoardLarge.GOLD_HEX
as returned from SOCBoardLarge.getHexTypeFromCoord(int)
.hex
- the hex coordinate IDpublic void undoUpdateNumbers(SOCPlayingPiece piece, SOCBoard board)
piece
- the playing pieceboard
- the game boardpublic void undoUpdateNumbers(int coord, SOCBoard board)
coord
- the node coordinateboard
- the game boardpublic void undoAddNumberForResource(int number, int resource, int hex)
number
- the dice-roll numberresource
- the resource, in range SOCResourceConstants.CLAY
to SOCResourceConstants.WOOD
,
from SOCBoard.getHexTypeFromCoord(int)
.
If hasSeaBoard
, can be SOCBoardLarge.GOLD_HEX
.hex
- the hex coordinate IDpublic boolean hasNumber(int number)
number
- the dice-roll number
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |