|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.game.SOCBoard
public class SOCBoard
This is a representation of the board in Settlers of Catan.
Board initialization is done in makeNewBoard(Map)
; that method
has some internal comments on structures, coordinates, layout and values.
Because some game variants may need different board layouts or features,
you may need a subclass of SOCBoard: Use
SOCBoard.BoardFactory.createBoard(Map, boolean, int)
whenever you need to construct a new SOCBoard.
A SOCGame
uses this board; the board is not given a reference to the game, to enforce layering
and keep the board logic simple. Game rules should be enforced at the game, not the board.
Calling board methods won't change the game state.
To identify nearby nodes, edges, hexes, etc, use the methods
with names such as getAdjacentHexesToNode(int)
.
Other methods to examine the board: SOCGame.getPlayersOnHex(int)
,
SOCGame.putPiece(SOCPlayingPiece)
, etc.
SOCBoardLarge
which has more geometry methods.
Coordinate system, as seen in appendix A of Robert S Thomas' dissertation:
Hexes (represented as coordinate of their centers), nodes (corners of hexes; where settlements/cities are placed), and edges (between nodes; where roads are placed), share the same grid of coordinates. Each hex is 2 units wide, in a 2-D coordinate system.
Current coordinate encodings: v1 (BOARD_ENCODING_ORIGINAL
),
v2 (BOARD_ENCODING_6PLAYER
), v3 (BOARD_ENCODING_LARGE
).
On the 4-player board: See src/docs/hexcoord.gif
Coordinates start with hex (1,1) on the far west, and go to (D,D) on the east.
The ring of water hexes surrounding land, is within these coordinates. (Land
hexes in that row are (3,3) to (B,B).
The first axis runs northwest to southeast; the second runs southwest to northeast.
Having six sides, hexes run in a straight line west to east, separated by vertical edges;
both coordinates increase along a west-to-east line.
All coordinates are encoded as two-digit hex integers, one digit per axis (thus 00 to FF). The center hex is encoded as 77; see the dissertation PDF's appendix for diagrams. Unfortunately this format means the board can't be expanded without changing its encoding, which is used across the network.
On the 6-player board: See src/docs/hexcoord-6player.gif
The 6-player board is rotated 90 degrees clockwise from the 4-player board,
so coordinates start with hex (1,1) as the northernmost land hex, and
hex (B,B) is the southernmost land hex. The ring of water hexes are outside
this coordinate grid.
For the large sea board (encoding v3: BOARD_ENCODING_LARGE
), see subclass SOCBoardLarge
.
Remember that ship pieces extend the SOCRoad
class.
Most methods of SOCBoard
, SOCGame
and SOCPlayer
differentiate them
(SOCPlayer.hasPotentialRoad()
vs SOCPlayer.hasPotentialShip()
),
but a few methods group them together:
SOCBoardLarge.getLandAreasLegalNodes()
!= null.
SOCBoardLarge
,
Serialized FormNested Class Summary | |
---|---|
static interface |
SOCBoard.BoardFactory
Board Factory for creating new boards for games at the client or server. |
static class |
SOCBoard.DefaultBoardFactory
Default implementation of SOCBoard.BoardFactory , used at client. |
Field Summary | |
---|---|
static int |
BOARD_ENCODING_6PLAYER
6-player format (v2) for getBoardEncodingFormat() :
Land hexes are same encoding as BOARD_ENCODING_ORIGINAL . |
static int |
BOARD_ENCODING_LARGE
Sea board format (v3) for getBoardEncodingFormat() :
Allows up to 127 x 127 board with an arbitrary mix of land and water tiles. |
static int |
BOARD_ENCODING_ORIGINAL
Original format (v1) for getBoardEncodingFormat() :
Hexadecimal 0x00 to 0xFF along 2 diagonal axes. |
protected int |
boardEncodingFormat
The encoding format of board coordinates, or BOARD_ENCODING_ORIGINAL (default, original). |
protected int |
boardHeight
Maximum valid coordinate value; size of board in coordinates (not in number of hexes across). |
protected int |
boardWidth
Maximum valid coordinate value; size of board in coordinates (not in number of hexes across). |
protected java.util.Vector<SOCCity> |
cities
cities on the board; Vector of SOCPlayingPiece |
static int |
CLAY_HEX
Clay; lowest-numbered hex type. |
static int |
CLAY_PORT
Clay port type. |
static int |
CLAY_PORT_HEX
|
static int |
DESERT_HEX
Desert; highest-numbered hex type. |
static int |
FACING_E
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int |
FACING_NE
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int |
FACING_NW
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int |
FACING_SE
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int |
FACING_SW
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int |
FACING_W
Facing is the direction (1-6) to the hex touching a hex or edge, or from a node to another node 2 nodes away. |
static int[] |
HEXCOORDS_LAND_V1
Land-hex coordinates in standard board ( BOARD_ENCODING_ORIGINAL ). |
static int[] |
HEXCOORDS_LAND_V2
Land-hex coordinates in 6-player board ( BOARD_ENCODING_6PLAYER ). |
private int[] |
hexIDtoNum
translate hex ID (hex coordinate) to an array index within hexLayout ,
which is sometimes called its "hex number". |
private int[] |
hexLayout
Hex data array, one element per water or land (or port, which is special water) hex. |
private static int[] |
HEXNODES
Offset to add to hex coordinate to get all adjacent node coords, starting at index 0 at the top (northern corner of hex) and going clockwise (RST dissertation figure A.5). |
protected static int[] |
makeNewBoard_diceNums_v1
Dice numbers in the original 4-player board layout, in order along numPath (makeNewBoard_numPaths_v1 ). |
protected static int[] |
makeNewBoard_diceNums_v2
Dice numbers in the 6-player board layout, in order along numPath (makeNewBoard_numPaths_v2 ). |
protected static int[] |
makeNewBoard_landHexTypes_v1
Land hex types on the original 4-player board layout (v1). |
protected static int[] |
makeNewBoard_landHexTypes_v2
Land hex types on the 6-player board layout (v2). |
private static int[][] |
makeNewBoard_numPaths_v1
Possible number paths for 4-player original board. |
private static int[][] |
makeNewBoard_numPaths_v2
Possible number paths for 6-player board. |
static int |
MAX_BOARD_ENCODING
Largest value of getBoardEncodingFormat() supported in this version. |
private static int |
MAX_LAND_HEX
Highest-numbered land hex type ( DESERT_HEX ). |
int |
max_robber_hextype
Maximum hex type value for the robber; can be used for array sizing. |
private int |
maxEdge
Minimum and maximum edge and node coordinates in this board's encoding. |
protected static int |
MAXEDGE_V1
largest coordinate value for an edge, in the v1 encoding. |
protected static int |
MAXEDGE_V2
largest coordinate value for an edge, in the v2 encoding |
protected static int |
MAXHEX
largest coordinate value for a hex, in the current encoding. |
private static int |
MAXNODE
largest coordinate value for a node on land, in the v1 and v2 encodings |
private int |
minEdge
Minimum and maximum edge and node coordinates in this board's encoding. |
protected static int |
MINEDGE_V1
smallest coordinate value for an edge, in the v1 encoding. |
protected static int |
MINEDGE_V2
smallest coordinate value for an edge, in the v2 encoding |
protected static int |
MINHEX
smallest coordinate value for a hex, in the current encoding. |
private int |
minNode
Minimum and maximum edge and node coordinates in this board's encoding. |
protected static int |
MINNODE_V1
smallest coordinate value for a node on land, in the v1 encoding. |
protected static int |
MINNODE_V2
smallest coordinate value for a node on land, in the v2 encoding |
static int |
MISC_PORT
Misc (3-for-1) port; lowest-numbered port-type integer. |
static int |
MISC_PORT_HEX
Misc (3-for-1) port type; lowest-numbered port-hextype integer |
private static int[] |
NODE_2_AWAY
Offsets from a node to another node 2 away, indexed by the facing directions: FACING_NE is 1,
FACING_E is 2, etc; FACING_NW is 6. |
protected java.util.HashMap<java.lang.Integer,java.lang.Integer> |
nodeIDtoPortType
translate node ID (node coordinate) to a port's type ( MISC_PORT to WOOD_PORT ). |
protected java.util.HashSet<java.lang.Integer> |
nodesOnLand
a list of nodes on the land of the board; key is node's Integer coordinate, value is Boolean. |
private int[] |
numberLayout
Dice number from hex numbers. |
private int[] |
numToHexID
Hex coordinates ("IDs") of each hex number ("hex number" means index within hexLayout ). |
static int |
ORE_HEX
|
static int |
ORE_PORT
Ore port type. |
static int |
ORE_PORT_HEX
|
private static java.lang.String[][] |
PORT_DESC_FOR_TYPE
String keys without/with articles for each port type, for getPortDescForType(int, boolean) . |
protected java.util.Vector<java.lang.Integer>[] |
ports
where the ports of each type are; coordinates per port type. |
private static int[] |
PORTS_EDGE_V1
Each port's 2 node coordinates on standard board. |
private static int[] |
PORTS_EDGE_V2
Each port's edge coordinate on the 6-player board. |
private static int[] |
PORTS_FACING_V1
Each port's facing towards land, on the standard board. |
private static int[] |
PORTS_FACING_V2
Each port's facing, on 6-player board. |
private static int[] |
PORTS_HEXNUM_V1
Each port's hex number within hexLayout on standard board. |
protected static int[] |
PORTS_TYPE_V1
Each port's type, such as SHEEP_PORT , on standard board. |
protected static int[] |
PORTS_TYPE_V2
Each port's type, such as SHEEP_PORT , on 6-player board. |
protected int[] |
portsLayout
Port information; varies by board layout encoding format. |
private int |
prevRobberHex
the previous hex coordinate that the robber is in; -1 unless setRobberHex(rh, true) was called. |
protected java.util.Random |
rand
random number generator |
protected java.util.Vector<SOCRoad> |
roads
roads on the board; Vector of SOCPlayingPiece. |
private int |
robberHex
the hex coordinate that the robber is in, or -1; placed on desert in makeNewBoard(Map) . |
private static long |
serialVersionUID
|
protected java.util.Vector<SOCSettlement> |
settlements
settlements on the board; Vector of SOCPlayingPiece |
static int |
SHEEP_HEX
|
static int |
SHEEP_PORT
Sheep port type. |
static int |
SHEEP_PORT_HEX
|
static int |
WATER_HEX
Water hex; lower-numbered than all land hex types. |
static int |
WHEAT_HEX
|
static int |
WHEAT_PORT
Wheat port type. |
static int |
WHEAT_PORT_HEX
|
static int |
WOOD_HEX
Wood. |
static int |
WOOD_PORT
Wood port type; highest-numbered port-type integer. |
static int |
WOOD_PORT_HEX
Wood port type; highest-numbered port-hextype integer |
Constructor Summary | |
---|---|
protected |
SOCBoard(int boardEncodingFmt,
int maxRobberHextype)
Minimal super constructor for subclasses. |
protected |
SOCBoard(java.util.Map<java.lang.String,SOCGameOption> gameOpts,
int maxPlayers)
Create a new Settlers of Catan Board, with the v1 or v2 encoding. |
Method Summary | |
---|---|
java.lang.String |
edgeCoordToString(int edge)
Get the dice roll numbers for hexes on either side of this edge. |
java.util.Vector<java.lang.Integer> |
getAdjacentEdgesToEdge(int coord)
Get the edge coordinates of the 2 to 4 edges adjacent to this edge. |
int[] |
getAdjacentEdgesToNode_arr(int coord)
Get the valid edge coordinates adjacent to this node. |
java.util.Vector<java.lang.Integer> |
getAdjacentEdgesToNode(int coord)
Get the valid edge coordinates adjacent to this node. |
int |
getAdjacentEdgeToNode(int nodeCoord,
int nodeDir)
Given a node, get the valid adjacent edge in a given direction, if any. |
int |
getAdjacentEdgeToNode2Away(int node,
int node2away)
Given an initial node, and a second node 2 nodes away, calculate the edge coordinate (adjacent to the initial node) going towards the second node. |
private void |
getAdjacentHexes_AddIfOK(java.util.Vector<java.lang.Integer> addTo,
boolean includeWater,
int hexCoord,
int d1,
int d2)
Check one possible coordinate for getAdjacentHexesToHex. |
java.util.Vector<java.lang.Integer> |
getAdjacentHexesToHex(int hexCoord,
boolean includeWater)
Make a list of all valid hex coordinates (or, only land) adjacent to this hex. |
java.util.Vector<java.lang.Integer> |
getAdjacentHexesToNode(int coord)
Get the coordinates of the valid hexes adjacent to this node. |
int |
getAdjacentHexToEdge(int edgeCoord,
int facing)
The hex touching an edge in a given direction, either along its length or at one end node. |
int |
getAdjacentNodeFarEndOfEdge(int edgeCoord,
int nodeCoord)
Get an edge's other adjacent node (its other end). |
int[] |
getAdjacentNodesToEdge_arr(int coord)
Adjacent node coordinates to an edge. |
java.util.Vector<java.lang.Integer> |
getAdjacentNodesToEdge(int coord)
Adjacent node coordinates to an edge, within valid range to be on the board. |
int[] |
getAdjacentNodesToHex(int hexCoord)
The node coordinates adjacent to this hex in all 6 directions. |
int[] |
getAdjacentNodesToNode_arr(int coord)
Get the valid node coordinates adjacent to this node. |
java.util.Vector<java.lang.Integer> |
getAdjacentNodesToNode(int coord)
Get the valid node coordinates adjacent to this node. |
int |
getAdjacentNodeToHex(int hexCoord,
int dir)
The node coordinate adjacent to this hex in a given direction. |
int |
getAdjacentNodeToNode(int nodeCoord,
int nodeDir)
Given a node, get the valid adjacent node in a given direction, if any. |
int |
getAdjacentNodeToNode2Away(int nodeCoord,
int facing)
Get the coordinate of another node 2 away, based on a starting node. |
int |
getBoardEncodingFormat()
Get the encoding format of this board (for coordinates, etc). |
int |
getBoardHeight()
Height of this board in coordinates (not in number of hexes across.) The maximum row coordinate. |
int |
getBoardWidth()
Width of this board in coordinates (not in number of hexes across.) The maximum column coordinate. |
java.util.Vector<SOCCity> |
getCities()
get the list of cities |
int |
getEdgeBetweenAdjacentNodes(int nodeA,
int nodeB)
Given a pair of adjacent node coordinates, get the edge coordinate that connects them. |
int[] |
getHexLayout()
|
int |
getHexNumFromCoord(int hexCoord)
Given a hex coordinate, return the hex number (index). |
int |
getHexTypeFromCoord(int hex)
Given a hex coordinate, return the type of hex |
int |
getHexTypeFromNumber(int hex)
Given a hex number, return the type of hex |
int[] |
getLandHexCoords()
The hex coordinates of all land hexes. |
int[] |
getNumberLayout()
The dice-number layout of dice rolls at each hex number. |
int |
getNumberOnHexFromCoord(int hex)
Given a hex coordinate, return the dice-roll number on that hex |
int |
getNumberOnHexFromNumber(int hex)
Given a hex number (index), return the (dice-roll) number on that hex |
java.util.Vector<java.lang.Integer> |
getPortCoordinates(int portType)
|
static java.lang.String |
getPortDescForType(int portType,
boolean withArticle)
Descriptive text key for a given port type, for i18n SOCStringManager.get(key) . |
int |
getPortsCount()
Get the number of ports on this board. |
int[] |
getPortsEdges()
Each port's edge coordinate. |
int[] |
getPortsFacing()
Each port's facing, such as FACING_NW . |
int[] |
getPortsLayout()
On the 6-player (v2 layout) board, each port's type, such as SHEEP_PORT . |
private int |
getPortTypeFromHexType(int hexType)
Given a hex type, return the port type. |
int |
getPortTypeFromNodeCoord(int nodeCoord)
What type of port is at this node? |
int |
getPreviousRobberHex()
If the robber has been moved by calling setRobberHex(int, boolean)
where rememberPrevious == true, get the previous coordinate
of the robber. |
java.util.Vector<SOCRoad> |
getRoads()
get the list of roads and ships |
int |
getRobberHex()
|
java.util.Vector<SOCSettlement> |
getSettlements()
get the list of settlements |
private void |
initHexIDtoNumAux(int begin,
int end,
int num)
Auxiliary method for initializing part of the hexIDtoNum array. |
private void |
initNodesOnLand()
As part of the constructor, check the boardEncodingFormat
and initialize nodesOnLand accordingly. |
(package private) java.util.HashSet<java.lang.Integer> |
initPlayerLegalAndPotentialSettlements()
Create and initialize a SOCPlayer 's set of legal settlements. |
(package private) java.util.HashSet<java.lang.Integer> |
initPlayerLegalRoads()
Create and initialize a SOCPlayer 's legalRoads set. |
boolean |
isEdgeAdjacentToNode(int nodeCoord,
int edgeCoord)
Determine if this node and edge are adjacent. |
boolean |
isHexOnLand(int hexCoord)
Is this the coordinate of a land hex (not water)? |
boolean |
isHexOnWater(int hexCoord)
Is this the coordinate of a water hex (not land)? |
boolean |
isNode2AwayFromNode(int n1,
int n2)
Determine if these 2 nodes are 2 nodes apart on the board, by the node coordinate arithmetic. |
boolean |
isNodeAdjacentToNode(int nodeA,
int nodeB)
Are these nodes adjacent to each other? |
boolean |
isNodeOnLand(int node)
|
protected boolean |
makeNewBoard_checkLandHexResourceClumps(java.util.Vector<java.lang.Integer> unvisited,
int clumpSize)
Depth-first search to check land hexes for resource clumps. |
private void |
makeNewBoard_placeHexes(int[] landHex,
int[] numPath,
int[] number,
SOCGameOption optBC)
For makeNewBoard(Map) , place the land hexes, number, and robber,
after shuffling landHex[]. |
protected void |
makeNewBoard_shufflePorts(int[] portHex,
SOCGameOption opt_breakClumps)
For makeNewBoard, shuffle portHex[]. |
void |
makeNewBoard(java.util.Map<java.lang.String,SOCGameOption> opts)
Shuffle the hex tiles and layout a board. |
java.lang.String |
nodeCoordToString(int node)
Get the dice roll numbers for hexes adjacent to this node. |
protected void |
placePort(int ptype,
int hex,
int face,
int node1,
int node2)
Auxiliary method for placing the port hexes, changing an element of hexLayout
and setting 2 elements of nodeIDtoPortType . |
void |
putPiece(SOCPlayingPiece pp)
Put a piece on the board. |
void |
removePiece(SOCPlayingPiece piece)
remove a piece from the board. |
SOCRoad |
roadAtEdge(int edgeCoord)
If there's a road or ship placed at this edge, find it. |
protected void |
setBoardBounds(int boardH,
int boardW)
For subclass constructor usage, set the board height and width. |
void |
setBoardEncodingFormat(int fmt)
set the board encoding format. |
void |
setHexLayout(int[] hl)
set the hexLayout. |
void |
setNumberLayout(int[] nl)
Set the number layout. |
void |
setPortsLayout(int[] portTypes)
On the 6-player (v2 layout) board, each port's type, such as SHEEP_PORT . |
void |
setRobberHex(int rh,
boolean rememberPrevious)
set where the robber is |
SOCPlayingPiece |
settlementAtNode(int nodeCoord)
If there's a settlement or city at this node, find it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
public static final int WATER_HEX
isHexOnLand(int)
,
isHexOnWater(int)
,
CLAY_HEX
,
MAX_LAND_HEX
,
Constant Field Valuespublic static final int CLAY_HEX
SOCResourceConstants.CLAY
.
WATER_HEX
,
Constant Field Valuespublic static final int ORE_HEX
public static final int SHEEP_HEX
public static final int WHEAT_HEX
public static final int WOOD_HEX
SOCResourceConstants.WOOD
.
public static final int DESERT_HEX
MAX_LAND_HEX
for the v1 and v2 board encodings.
Before v2.0.00, value was 0 instead of 6.
private static final int MAX_LAND_HEX
DESERT_HEX
).
The v3 encoding has a higher SOCBoardLarge.GOLD_HEX
and SOCBoardLarge.FOG_HEX
,
but they aren't encodable in this class (v1 or v2 encoding) because of MISC_PORT_HEX
.
isHexOnLand(int)
,
isHexOnWater(int)
,
WATER_HEX
,
Constant Field Valuespublic static final int MISC_PORT_HEX
public static final int CLAY_PORT_HEX
public static final int ORE_PORT_HEX
public static final int SHEEP_PORT_HEX
public static final int WHEAT_PORT_HEX
public static final int WOOD_PORT_HEX
public static final int MISC_PORT
Other code such as SOCBoardPanel.drawHex relies on the
fact that MISC_PORT
== 0 == WATER_HEX
,
and that the range CLAY_PORT
- WOOD_PORT
are 1 - 5,
and CLAY_HEX
== CLAY_PORT
.
public static final int CLAY_PORT
CLAY_HEX
.
public static final int ORE_PORT
ORE_HEX
.
public static final int SHEEP_PORT
SHEEP_HEX
.
public static final int WHEAT_PORT
WHEAT_HEX
.
public static final int WOOD_PORT
WOOD_HEX
.
public static final int FACING_NE
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
public static final int FACING_E
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
public static final int FACING_SE
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
public static final int FACING_SW
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
public static final int FACING_W
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
public static final int FACING_NW
hexLayout
for ports, and elsewhere.6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
protected static final int[] PORTS_TYPE_V1
SHEEP_PORT
, on standard board.
Same order as PORTS_FACING_V1
. MISC_PORT
is 0.
private static final int[] PORTS_HEXNUM_V1
hexLayout
on standard board.
Same order as PORTS_FACING_V1
:
Clockwise from upper-left (hex coordinate 0x17).
private static final int[] PORTS_FACING_V1
FACING_E
), 3 is SE, 4 is SW, etc; see hexLayout
.
private static final int[] PORTS_EDGE_V1
PORTS_FACING_V1
:
Clockwise from upper-left (hex coordinate 0x17).
protected static final int[] PORTS_TYPE_V2
SHEEP_PORT
, on 6-player board.
Same order as PORTS_FACING_V2
. MISC_PORT
is 0.
private static final int[] PORTS_FACING_V2
FACING_E
), 3 is SE, 4 is SW, etc.
private static final int[] PORTS_EDGE_V2
PORTS_FACING_V2
:
Clockwise from upper-left (hex coordinate 0x17, which is land in the V2 layout).
public static final int BOARD_ENCODING_ORIGINAL
getBoardEncodingFormat()
:
Hexadecimal 0x00 to 0xFF along 2 diagonal axes.
Coordinate range on each axis is 0 to 15 decimal. In hex:Hexes: 11 to DD Nodes: 01 or 10, to FE or EF Edges: 00 to EE
See the Dissertation PDF for details.
public static final int BOARD_ENCODING_6PLAYER
getBoardEncodingFormat()
:
Land hexes are same encoding as BOARD_ENCODING_ORIGINAL
.
Land starts 1 extra hex west of standard board,
and has an extra row of land at north and south end.
Ports are not part of hexLayout
because their
coordinates wouldn't fit within 2 hex digits.
Instead, see getPortTypeFromNodeCoord(int)
,
getPortsEdges()
, getPortsFacing()
,
getPortCoordinates(int)
or getPortsLayout()
.
public static final int BOARD_ENCODING_LARGE
getBoardEncodingFormat()
:
Allows up to 127 x 127 board with an arbitrary mix of land and water tiles.
Land, water, and port locations/facings are no longer hardcoded.
Use getPortsCount()
to get the number of ports.
For other port information, use the same methods as in BOARD_ENCODING_6PLAYER
.
Activated with SOCGameOption
"SBL"
.
SOCBoardLarge
,
Constant Field Valuespublic static final int MAX_BOARD_ENCODING
getBoardEncodingFormat()
supported in this version.
protected int boardWidth
Hexes: 11 to DD Nodes: 01 or 10, to FE or EF Edges: 00 to EEAlthough this field is protected (not private), please treat it as read-only.
protected int boardHeight
Hexes: 11 to DD Nodes: 01 or 10, to FE or EF Edges: 00 to EEAlthough this field is protected (not private), please treat it as read-only.
private int minNode
MAXNODE
is the same in the v1 and v2 current encodings.)
Not used in v3 (BOARD_ENCODING_LARGE
).
private int minEdge
MAXNODE
is the same in the v1 and v2 current encodings.)
Not used in v3 (BOARD_ENCODING_LARGE
).
private int maxEdge
MAXNODE
is the same in the v1 and v2 current encodings.)
Not used in v3 (BOARD_ENCODING_LARGE
).
protected int boardEncodingFormat
BOARD_ENCODING_ORIGINAL
(default, original).
The board size determines the required encoding format.
hexLayout
.
portsLayout
.
Added in 1.1.08.
BOARD_ENCODING_LARGE
).
Coordinate range for rows,columns is each 0 to 255 decimal,
or altogether 0x0000 to 0xFFFF hex.
Arbitrary mix of land and water tiles.
Added in 2.0.00, implemented in SOCBoardLarge
.
Activated with SOCGameOption
"SBL".
protected static final int MAXHEX
protected static final int MINHEX
protected static final int MAXEDGE_V1
MAXEDGE_V2
represents a different encoding.
protected static final int MAXEDGE_V2
protected static final int MINEDGE_V1
MINEDGE_V2
has a different value.
protected static final int MINEDGE_V2
private static final int MAXNODE
protected static final int MINNODE_V1
MINNODE_V2
has a different value.
protected static final int MINNODE_V2
public static final int[] HEXCOORDS_LAND_V1
BOARD_ENCODING_ORIGINAL
).
public static final int[] HEXCOORDS_LAND_V2
BOARD_ENCODING_6PLAYER
).
private int[] hexLayout
numToHexID
[i].
Each element's value encodes hex type and, if a
port, its facing (FACING_NE
to FACING_NW
).
For land hexes, the dice number on hexLayout[i] is numberLayout
[i].
Key to the hexLayout[] values:
Note that hexLayout contains ports only for the v1 encoding (BOARD_ENCODING_ORIGINAL
);
v2 and v3 use portsLayout
instead, and hexLayout contains only water and the land
hex types. The v3 encoding (BOARD_ENCODING_LARGE
) doesn't use hexLayout
at all,
instead it has a 2-dimensional hexLayoutLg
structure.
0 : waterNon-misc ports are encoded here in binary like this:WATER_HEX
(was 6 before v2.0.00) 1 : clayCLAY_HEX
2 : oreORE_HEX
3 : sheepSHEEP_HEX
4 : wheatWHEAT_HEX
5 : woodWOOD_HEX
6 : desertDESERT_HEX
(was 0 before v2.0.00) also:MAX_LAND_HEX
7 : misc port ("3:1") facing land in direction 1 (NorthEast
) (this port type isMISC_PORT
ingetPortTypeFromNodeCoord(int)
) 8 : misc port facing 2 (FACING_E
) 9 : misc port facing 3 (FACING_SE
) 10 : misc port facing 4 (FACING_SW
) 11 : misc port facing 5 (FACING_W
) 12 : misc port facing 6 (NorthWest
) 16+: non-misc ("2:1") encoded port
(port facing, 1-6) (kind of port) \--> [0 0 0][0 0 0 0] <--/Kind of port:
1 : clay (port typePort facing is the edge of the port's hex touching land, which contains 2 nodes where player can build a port settlement/city; facing is a number 1-6 (CLAY_PORT
ingetPortTypeFromNodeCoord(int)
) 2 : oreORE_PORT
3 : sheepSHEEP_PORT
4 : wheatWHEAT_PORT
5 : woodWOOD_PORT
FACING_NE
-FACING_NW
). 6 <--. .--> 1 \/\/ / \ 5<--| |--> 2 | | \ / /\/\ 4 <--. .--> 3
For board encoding formats BOARD_ENCODING_ORIGINAL
and
BOARD_ENCODING_6PLAYER
, hexLayout indexes are arranged
this way per numToHexID
:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36The 6-player board is visually rotated clockwise 90 degrees; the client's visual "North" (index 15, hex coordinate 0x11) on that board is West internally in the board layout.
getHexTypeFromNumber(int)
,
getAdjacentNodeToHex(int, int)
protected int[] portsLayout
makeNewBoard(Map)
if not null.
hexLayout
instead,
and this field is null.
hexLayout
.
1 element per port. Same ordering as PORTS_FACING_V2
.
BOARD_ENCODING_LARGE
stores more information
within the port layout array. n = getPortsCount()
.
The port types are stored at the beginning, from index 0 to n - 1.
The next n indexes store each port's edge coordinate.
The next n store each port's facing (towards land).
One scenario there has movable ports; a port's edge might temporarily be -1. Ignore this port if so, it's not currently placed on the board.
ports
private int[] numberLayout
numToHexID
numberLayout[i] is the dice number for the land hex stored in hexLayout
[i].
The robber hex is 0. Water hexes are -1.
Used in the v1 and v2 encodings (ORIGINAL, 6PLAYER).
The v3 encoding (BOARD_ENCODING_LARGE
) doesn't use this array,
instead it uses SOCBoardLarge.numberLayoutLg
.
private int[] numToHexID
hexLayout
).
BOARD_ENCODING_ORIGINAL
: The hexes in here are the board's land hexes and also
the surrounding ring of water/port hexes.
BOARD_ENCODING_6PLAYER
: The hexes in here are the board's land hexes and also
the unused hexes (rightmost column: 7D - DD - D7).
BOARD_ENCODING_LARGE
: Does not use numToHexID or hexLayout; hex coordinate == hex number.
hexIDtoNum
,
nodesOnLand
,
HEXCOORDS_LAND_V1
,
HEXCOORDS_LAND_V2
,
getLandHexCoords()
private int[] hexIDtoNum
hexLayout
,
which is sometimes called its "hex number".
The numbers in here are the board's land hexes and also the surrounding
ring of water/port hexes. Initialized in constructor. Length is >= MAXHEX
.
A value of -1 means the ID isn't a valid hex number on the board.
numToHexID
,
nodeIDtoPortType
protected java.util.HashMap<java.lang.Integer,java.lang.Integer> nodeIDtoPortType
MISC_PORT
to WOOD_PORT
).
Initialized in makeNewBoard(Map)
.
Key = node coordinate as Integer; value = port type as Integer.
If the node ID isn't present, that coordinate isn't a valid port on the board.
ports
,
portsLayout
,
hexIDtoNum
private static final int[] HEXNODES
private static final int[] NODE_2_AWAY
FACING_NE
is 1,
FACING_E
is 2, etc; FACING_NW
is 6.
Used by getAdjacentNodeToNode2Away(int, int)
.
See RST dissertation figure A.2.
private int robberHex
makeNewBoard(Map)
.
Once the robber is placed on the board, it cannot be removed (cannot become -1 again).
private int prevRobberHex
setRobberHex(rh, true)
was called.
public final int max_robber_hextype
getHexTypeFromCoord(int)
for the current board encoding.
SOCGame.canMoveRobber(int, int)
protected java.util.Vector<java.lang.Integer>[] ports
MISC_PORT
to WOOD_PORT
.
Values are Vectors of Integer node coordinates; each port
will have 2 Integers because it touches 2 nodes.
So, the number of ports of a type is ports[type].size() / 2.
portsLayout
,
getPortsEdges()
protected java.util.Vector<SOCRoad> roads
SOCBoardLarge
), also
contains all ships on the board.
protected java.util.Vector<SOCSettlement> settlements
protected java.util.Vector<SOCCity> cities
protected java.util.Random rand
protected java.util.HashSet<java.lang.Integer> nodesOnLand
See dissertation figure A.2.
See also initPlayerLegalAndPotentialSettlements()
and getLandHexCoords()
.
On the large sea board, there can optionally be multiple "land areas"
(groups of islands), if SOCBoardLarge.getLandAreasLegalNodes()
!= null.
In that case, nodesOnLand contains all nodes of all land areas.
private static final int[][] makeNewBoard_numPaths_v1
makeNewBoard(Map)
randomly chooses one path (one 1-dimensional array)
to be used as numPath[] in
makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
private static final int[][] makeNewBoard_numPaths_v2
makeNewBoard(Map)
randomly chooses one path (one 1-dimensional array)
to be used as numPath[] in
makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
protected static final int[] makeNewBoard_landHexTypes_v1
makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
protected static final int[] makeNewBoard_diceNums_v1
numPath
(makeNewBoard_numPaths_v1
).
For more information see makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
protected static final int[] makeNewBoard_landHexTypes_v2
makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
protected static final int[] makeNewBoard_diceNums_v2
numPath
(makeNewBoard_numPaths_v2
).
For more information see makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
private static final java.lang.String[][] PORT_DESC_FOR_TYPE
getPortDescForType(int, boolean)
.
Index 0 == MISC_PORT
, 1 == CLAY_PORT
, etc.
Constructor Detail |
---|
protected SOCBoard(int boardEncodingFmt, int maxRobberHextype) throws java.lang.IllegalArgumentException
boardEncodingFormat
, robberHex
, prevRobberHex
.
Creates empty Vectors for roads
, settlements
,
cities
and ports
, but not portsLayout
.
Creates an empty HashSet for nodesOnLand
.
Most likely you should also call setBoardBounds(int, int)
.
boardEncodingFmt
- A format constant in the currently valid range:
Must be >= BOARD_ENCODING_ORIGINAL
and <= MAX_BOARD_ENCODING
.maxRobberHextype
- Maximum land hextype value, or maximum hex type
the robber can be placed at. Same value range as max_robber_hextype
and as your subclass's getHexTypeFromCoord(int)
method.
java.lang.IllegalArgumentException
- if boardEncodingFmt is out of rangeprotected SOCBoard(java.util.Map<java.lang.String,SOCGameOption> gameOpts, int maxPlayers) throws java.lang.IllegalArgumentException
SOCBoardLarge
constructor.)
gameOpts
- if game has options, map of SOCGameOption
; otherwise null.maxPlayers
- Maximum players; must be 4 or 6. (Added in 1.1.08)
java.lang.IllegalArgumentException
- if maxPlayers is not 4 or 6SOCBoard.BoardFactory.createBoard(Map, boolean, int)
Method Detail |
---|
private void initNodesOnLand()
boardEncodingFormat
and initialize nodesOnLand
accordingly.
initPlayerLegalAndPotentialSettlements()
private final void initHexIDtoNumAux(int begin, int end, int num)
begin
- Beginning of coordinate rangeend
- Ending coordinate - same horizontal row as beginnum
- Number to assign to first hexIDtoNum
[] within this coordinate range;
corresponds to hex's index ("hex number") within hexLayout
.public void makeNewBoard(java.util.Map<java.lang.String,SOCGameOption> opts)
setHexLayout(int[])
or SOCBoardLarge.setLandHexLayout(int[])
.
opts
- Game options
, which may affect
tile placement on board, or null. opts must be
the same as passed to constructor, and thus give the same size and layout
(same getBoardEncodingFormat()
).private final void makeNewBoard_placeHexes(int[] landHex, int[] numPath, int[] number, SOCGameOption optBC) throws java.lang.IllegalArgumentException
makeNewBoard(Map)
, place the land hexes, number, and robber,
after shuffling landHex[].
Sets robberHex, contents of hexLayout[] and numberLayout[].
Also checks vs game option BC: Break up clumps of # or more same-type hexes/ports
(for land hex resource types).
Called from makeNewBoard(Map)
at server only; client has its board layout sent from the server.
This method does not clear out hexLayout
or numberLayout
before it starts placement. Since hexLayout's land hex coordinates are hardcoded within
numToHexID
, it can only be called once per board layout.
landHex
- Resource type to place into hexLayout
for each land hex; will be shuffled.
Values are CLAY_HEX
, DESERT_HEX
, etc.numPath
- Indexes within hexLayout
(also within numberLayout
) for each land hex;
same array length as landHex[]number
- Numbers to place into numberLayout
for each land hex;
array length is landHex[].length minus 1 for each desert in landHex[]optBC
- Game option "BC" from the options for this board, or null.
java.lang.IllegalArgumentException
- if makeNewBoard_checkLandHexResourceClumps(Vector, int)
finds an invalid or uninitialized hex coordinate (hex type -1)protected boolean makeNewBoard_checkLandHexResourceClumps(java.util.Vector<java.lang.Integer> unvisited, int clumpSize) throws java.lang.IllegalArgumentException
Start with the set of all land hexes, and consider them 'unvisited'. Look at each hex in the set, marking them as visited and moving them into new subsets ("clumps") composed of adjacent hexes of the same resource type. Build clumps by immediately visiting those adjacent hexes, and their unvisited same-type adjacents, etc. Once we've visited each hex, check if any clump subset's size is larger than the allowed size.
For the Fog Island (scenario option _SC_FOG on SOCBoardLarge
),
one land area contains some water. So, unvisited may contain
a few water hexes. For performance, in general you should omit water
hex locations from unvisited.
Called from makeNewBoard_placeHexes(int[], int[], int[], SOCGameOption)
.
Before v2.0.00, this was part of makeNewBoard_placeHexes.
unvisited
- Contains each land hex's coordinate as an Integer;
Note: This vector will be modified by the method. clumpSize
- Clumps of this size or more are too large.
Minimum value is 3, smaller values will always return false.
java.lang.IllegalArgumentException
- if a hex type is -1 (uninitialized or not a valid hex coordinate)protected void makeNewBoard_shufflePorts(int[] portHex, SOCGameOption opt_breakClumps) throws java.lang.IllegalStateException
portHex
- Contains port types, 1 per port, as they will appear in clockwise
order around the edge of the board. Must not all be the same type.
MISC_PORT
is the 3-for-1 port type value.opt_breakClumps
- Game option "BC", or null
java.lang.IllegalStateException
- if opt_breakClumps is set, and all portHex[] elements have the same valueprotected final void placePort(int ptype, int hex, int face, int node1, int node2)
hexLayout
and setting 2 elements of nodeIDtoPortType
.
Adds the 2 nodes to ports
[ptype].
ptype
- Port type; in range MISC_PORT
to WOOD_PORT
.hex
- Hex number (index) within hexLayout
, or -1 if
BOARD_ENCODING_6PLAYER
or if you don't want to change
hexLayout[hex]'s value.face
- Facing of port towards land; 1 to 6 (FACING_NE
to FACING_NW
).
Ignored if hex == -1.node1
- Node coordinate 1 of portnode2
- Node coordinate 2 of portjava.util.HashSet<java.lang.Integer> initPlayerLegalRoads()
SOCPlayer
's legalRoads set.
Previously part of SOCPlayer
, but moved here in version 1.1.12
to better encapsulate the board coordinate encoding.
Note: If your board is board layout v3 (SOCBoardLarge
):
Because the v3 board layout varies:
At the server, call this after makeNewBoard(Map)
.
At the client, call this after
SOCBoardLarge.setLegalAndPotentialSettlements(java.util.Collection, int, HashSet[])
.
Integer
sjava.util.HashSet<java.lang.Integer> initPlayerLegalAndPotentialSettlements()
SOCPlayer
's set of legal settlements.
For v1 and v2, you can clone the returned legalSettlements to potentialSettlements.
For v3 (SOCBoardLarge
), the potentials may be only a subset of
legalSettlements; after makeNewBoard(Map)
, call
SOCBoardLarge.getLegalAndPotentialSettlements()
instead of this method.
Previously part of SOCPlayer
, but moved here in version 1.1.12
to better encapsulate the board coordinate encoding.
In encoding v1 and v2, this is always the same coordinates as nodesOnLand
.
nodesOnLand
public int[] getHexLayout() throws java.lang.UnsupportedOperationException
hexLayout
.
Please treat the returned array as read-only.
java.lang.UnsupportedOperationException
- if the board encoding doesn't support this method;
the v1 and v2 encodings do, but v3 (BOARD_ENCODING_LARGE
) does not.getLandHexCoords()
public int[] getLandHexCoords()
Before v2.0.00, this was getHexLandCoords().
public boolean isHexOnLand(int hexCoord)
hexCoord
- Hex coordinate, between 0 and MAXHEX
isHexOnWater(int)
public boolean isHexOnWater(int hexCoord)
hexCoord
- Hex coordinate, between 0 and MAXHEX
isHexOnLand(int)
public int[] getNumberLayout() throws java.lang.UnsupportedOperationException
BOARD_ENCODING_LARGE
).
For v3, call getLandHexCoords()
and getNumberOnHexFromCoord(int)
instead.
java.lang.UnsupportedOperationException
- if the board encoding doesn't support this method;
the v1 and v2 encodings do, but v3 (BOARD_ENCODING_LARGE
) does not.public int[] getPortsLayout()
SHEEP_PORT
.
Same value range as in hexLayout
.
(In the standard board (v1), these are part of hexLayout
instead.)
Same order as getPortsFacing()
: Clockwise from upper-left.
The number of ports is getPortsCount()
.
Note: The v3 layout (BOARD_ENCODING_LARGE
) stores more information
within the port layout array. The port types are stored at the beginning, from index
0 to getPortsCount()
-1. If you call setPortsLayout(int[])
, be sure
to give it the entire array returned from here.
getPortTypeFromNodeCoord(int)
,
getPortCoordinates(int)
public int[] getPortsFacing()
FACING_NW
.
Port Facing is the direction from the port hex, to the land hex touching it
which will have 2 nodes where a port settlement/city can be built.
Same order as getPortsLayout()
: Clockwise from upper-left.
The length of this array is always getPortsCount()
.
This method should not be called frequently.
getPortsEdges()
public int[] getPortsEdges()
getPortsLayout()
: Clockwise from upper-left.
The length of this array is always getPortsCount()
.
This method should not be called frequently.
A scenario of SOCBoardLarge
has movable ports; a port's edge there might
temporarily be -1. Ignore this port if so, it's not currently placed on the board.
This happens only with SOCBoardLarge
(layout encoding v3), not the original or 6-player
(v1 or v2) SOCBoard
layouts.
getPortsFacing()
,
getPortCoordinates(int)
public int getRobberHex()
getPreviousRobberHex()
,
SOCBoardLarge.getPirateHex()
public int getPreviousRobberHex()
setRobberHex(int, boolean)
where rememberPrevious == true, get the previous coordinate
of the robber.
getRobberHex()
public void setBoardEncodingFormat(int fmt) throws java.lang.IllegalArgumentException
fmt
- Board encoding format number
java.lang.IllegalArgumentException
- if fmt < 1 or > MAX_BOARD_ENCODING
public void setHexLayout(int[] hl) throws java.lang.UnsupportedOperationException
setBoardEncodingFormat(int)
first,
unless the format is BOARD_ENCODING_ORIGINAL
.
hl
- the hex layout.
For BOARD_ENCODING_ORIGINAL
: if hl[0] is WATER_HEX
,
the board is assumed empty and ports arrays won't be filled.
java.lang.UnsupportedOperationException
- if the board encoding doesn't support this method;
the v1 and v2 encodings do, but v3 (BOARD_ENCODING_LARGE
) does not.public void setPortsLayout(int[] portTypes)
SHEEP_PORT
.
(In the standard board (v1), these are part of hexLayout
instead.)
Same order as PORTS_FACING_V2
: Clockwise from upper-left.
Note: The v3 layout (BOARD_ENCODING_LARGE
) stores more information
within the port layout array. If you call setPortsLayout(int[])
, be sure
you are giving all information returned by getPortsLayout()
, not just the
port types.
getPortsLayout()
private final int getPortTypeFromHexType(int hexType)
BOARD_ENCODING_ORIGINAL
to set up port info in setHexLayout(int[])
.
hexType
- the hex type, as in hexLayout
MISC_PORT
to WOOD_PORT
.
If called on a non-port hex, returns 0
(which is MISC_PORT).getHexTypeFromCoord(int)
,
getPortTypeFromNodeCoord(int)
public void setNumberLayout(int[] nl) throws java.lang.UnsupportedOperationException
BOARD_ENCODING_LARGE
).
For v3, call SOCBoardLarge.setLandHexLayout(int[])
instead.
nl
- the number layout, from getNumberLayout()
java.lang.UnsupportedOperationException
- if the board encoding doesn't support this method;
the v1 and v2 encodings do, but v3 (BOARD_ENCODING_LARGE
) does not.public void setRobberHex(int rh, boolean rememberPrevious) throws java.lang.IllegalArgumentException
rh
- the new robber hex coordinate; must be > 0, not validated beyond thatrememberPrevious
- Should we remember the old robber hex? (added in 1.1.11)
java.lang.IllegalArgumentException
- if rh <= 0getRobberHex()
,
getPreviousRobberHex()
,
SOCBoardLarge.setPirateHex(int, boolean)
public int getPortsCount()
BOARD_ENCODING_LARGE
) has a varying amount of ports,
set during makeNewBoard(Map)
.
makeNewBoard(Map)
hasn't been called yet.public java.util.Vector<java.lang.Integer> getPortCoordinates(int portType)
portType
- the type of port;
in range MISC_PORT
to WOOD_PORT
.
getPortTypeFromNodeCoord(int)
,
getPortsLayout()
,
getPortsEdges()
public int getPortTypeFromNodeCoord(int nodeCoord)
nodeCoord
- the coordinates for a node
MISC_PORT
to WOOD_PORT
),
or -1 if no port at this nodegetPortDescForType(int, boolean)
public static java.lang.String getPortDescForType(int portType, boolean withArticle)
SOCStringManager.get(key)
.
From v1.1.08 through all v1.1.xx, this method was in SOCBoardPanel
.
portType
- Port type, as from getPortTypeFromNodeCoord(int)
.
Should be in range MISC_PORT
to WOOD_PORT
, or -1.withArticle
- If true, string key's value format is "a 2:1 clay port", if false "2:1 Clay port"
null
for -1 (no port at node).
Text format is "3:1 Port" or "2:1 Wood port". Defaults to generic type if portType
value is unknown.public int getNumberOnHexFromCoord(int hex)
hex
- the coordinates ("ID") for a hex
getNumberOnHexFromNumber(int)
public int getNumberOnHexFromNumber(int hex)
hex
- the number of a hex, or -1 if invalid
getNumberOnHexFromCoord(int)
public int getHexNumFromCoord(int hexCoord) throws java.lang.UnsupportedOperationException
hexCoord
- the coordinates ("ID") for a hex
java.lang.UnsupportedOperationException
- if the board encoding doesn't support this method;
the v1 and v2 encodings do, but v3 (BOARD_ENCODING_LARGE
) does not.getHexTypeFromCoord(int)
public int getHexTypeFromCoord(int hex)
hex
- the coordinates ("ID") for a hex
CLAY_HEX
to WOOD_HEX
,
or DESERT_HEX
,
or MISC_PORT_HEX
or another port type (CLAY_PORT_HEX
, etc),
or WATER_HEX
or -1 for invalid hex coordinategetHexNumFromCoord(int)
,
getLandHexCoords()
public int getHexTypeFromNumber(int hex)
hex
- the number of a hex (its index in hexLayout
, not its coordinate), or -1 for invalid
CLAY_HEX
to WOOD_HEX
,
DESERT_HEX
, or WATER_HEX
,
or MISC_PORT_HEX
or another port type (CLAY_PORT_HEX
, etc).
Invalid hex numbers return -1.getHexTypeFromCoord(int)
public void putPiece(SOCPlayingPiece pp)
Call this only after calling
pl.putPiece(pp, isTempPiece)
for each player.
pp
- Piece to place on the board; coordinates are not checked for validityremovePiece(SOCPlayingPiece)
public void removePiece(SOCPlayingPiece piece)
If you're calling SOCPlayer.undoPutPiece(SOCPlayingPiece)
,
call this method first.
piece
- Piece to be removed from the board
(identified by its piece type, coordinate, and player number)putPiece(SOCPlayingPiece)
public java.util.Vector<SOCRoad> getRoads()
public java.util.Vector<SOCSettlement> getSettlements()
public java.util.Vector<SOCCity> getCities()
public int getBoardWidth()
BOARD_ENCODING_ORIGINAL
.
public int getBoardHeight()
BOARD_ENCODING_ORIGINAL
.
protected void setBoardBounds(int boardH, int boardW)
boardH
- New maximum row coordinate, for getBoardHeight()
boardW
- New maximum column coordinate, for getBoardWidth()
public int getBoardEncodingFormat()
BOARD_ENCODING_ORIGINAL
public java.util.Vector<java.lang.Integer> getAdjacentNodesToEdge(int coord)
For v1 and v2 encoding, this range is MINNODE_V1
to MAXNODE
,
or MINNODE_V2
to MAXNODE
.
For v3 encoding, nodes are around all valid land or water hexes,
and the board size is getBoardHeight()
x getBoardHeight()
.
getAdjacentNodesToEdge_arr(int)
public int[] getAdjacentNodesToEdge_arr(int coord)
MINNODE_V1
to MAXNODE
,
so nodes in the water (off the land board) may be returned.
coord
- Edge coordinate; not checked for validity
getAdjacentNodesToEdge(int)
,
getAdjacentNodeFarEndOfEdge(int, int)
public int getAdjacentNodeFarEndOfEdge(int edgeCoord, int nodeCoord)
getAdjacentNodesToEdge_arr(int)
and
returns the node that isn't nodeCoord.
edgeCoord
- Edge coordinate; not checked for validitynodeCoord
- Node at one end of edgeCoord; the opposite end node
will be returned.
public java.util.Vector<java.lang.Integer> getAdjacentEdgesToEdge(int coord)
coord
- Edge coordinate; for the 6-player encoding, use 0, not -1, for edge 0x00.
Not checked for validity.
public java.util.Vector<java.lang.Integer> getAdjacentHexesToNode(int coord)
coord
- Node coordinate. Is not checked for validity.
public java.util.Vector<java.lang.Integer> getAdjacentEdgesToNode(int coord)
getAdjacentEdgeToNode(int, int)
.
getAdjacentEdgeToNode(int, int)
public final int[] getAdjacentEdgesToNode_arr(int coord)
getAdjacentEdgeToNode(int, int)
.
coord
- Node coordinate. Is not checked for validity.
public int getAdjacentEdgeToNode(int nodeCoord, int nodeDir) throws java.lang.IllegalArgumentException
In the 6-player layout, valid land nodes/edges are found on the outer ring of the board coordinate system, but some of their adjacent nodes/edges may be "off the board" and thus invalid.
nodeCoord
- Node coordinate to go from; not checked for validity.nodeDir
- 0 for northwest or southwest; 1 for northeast or southeast;
2 for north or south
java.lang.IllegalArgumentException
- if nodeDir is less than 0 or greater than 2getAdjacentEdgesToNode(int)
,
getEdgeBetweenAdjacentNodes(int, int)
,
getAdjacentNodeToNode(int, int)
public int getEdgeBetweenAdjacentNodes(int nodeA, int nodeB)
Does not check actual roads or other pieces on the board, only uses the calculations in Robert S Thomas' dissertation figures A.7 - A.10.
nodeA
- Node coordinate adjacent to nodeB; not checked for validitynodeB
- Node coordinate adjacent to nodeA; not checked for validity
getAdjacentEdgesToNode(int)
,
getAdjacentEdgeToNode(int, int)
public boolean isEdgeAdjacentToNode(int nodeCoord, int edgeCoord)
getAdjacentEdgesToNode(int)
,
so there may be a false positive, but not a false negative.
nodeCoord
- Node coordinate; not bounds-checkededgeCoord
- Edge coordinate; checked against minEdge, maxEdge.
For the 6-player encoding, use 0, not -1, to indicate edge 0x00.
getEdgeBetweenAdjacentNodes(int, int)
public java.util.Vector<java.lang.Integer> getAdjacentNodesToNode(int coord)
getAdjacentNodeToNode(int, int)
.
isNodeAdjacentToNode(int, int)
public final int[] getAdjacentNodesToNode_arr(int coord)
Calls getAdjacentNodeToNode(int, int)
.
coord
- Node coordinate. Is not checked for validity.
isNodeAdjacentToNode(int, int)
public final boolean isNodeAdjacentToNode(int nodeA, int nodeB)
nodeA
- One node coordinate; not validatednodeB
- Other node coordinate; not validated
getAdjacentNodesToNode(nodeA)
contains nodeBgetAdjacentNodesToNode(int)
public int getAdjacentNodeToNode(int nodeCoord, int nodeDir) throws java.lang.IllegalArgumentException
In the 6-player layout, valid land nodes/edges are found on the outer ring of the board coordinate system, but some of their adjacent nodes/edges may be "off the board" and thus invalid.
nodeCoord
- Node coordinate to go from; not checked for validity.nodeDir
- 0 for northwest or southwest; 1 for northeast or southeast;
2 for north or south
java.lang.IllegalArgumentException
- if nodeDir is less than 0 or greater than 2getAdjacentNodesToNode(int)
,
getAdjacentNodeToNode2Away(int, int)
,
getAdjacentEdgeToNode(int, int)
,
isNodeAdjacentToNode(int, int)
public int getAdjacentNodeToNode2Away(int nodeCoord, int facing) throws java.lang.IllegalArgumentException
FACING_NE
is 1,
FACING_E
is 2, etc; FACING_NW
is 6.
nodeCoord
- Starting node's coordinatefacing
- Facing from node; 1 to 6.
This will be one of the 6 directions
from a node to another node 2 away.
Facing 2 is FACING_E
, 3 is FACING_SE
, 4 is SW, etc.
on the board
.
java.lang.IllegalArgumentException
- if facing < 1 or facing > 6getAdjacentNodeToNode(int, int)
,
getAdjacentEdgeToNode2Away(int, int)
,
isNode2AwayFromNode(int, int)
public boolean isNode2AwayFromNode(int n1, int n2)
n1
- Node coordinate; not validatedn2
- Node coordinate; not validated
getAdjacentNodeToNode2Away(int, int)
public int getAdjacentEdgeToNode2Away(int node, int node2away)
node
- Initial node coordinate; not validatednode2away
- Second node coordinate; should be 2 away,
but this is not validated
getAdjacentNodeToNode2Away(int, int)
public java.util.Vector<java.lang.Integer> getAdjacentHexesToHex(int hexCoord, boolean includeWater)
MINHEX
to MAXHEX
, and valid according to getHexNumFromCoord(int)
.
Coordinate offsets, from Dissertation figure A.4 - adjacent hexes to hex:
(-2,0) (0,+2) (-2,-2) x (+2,+2) (0,-2) (+2,0)
hexCoord
- Coordinate ("ID") of this hex; not checked for validityincludeWater
- Should water hexes be returned (not only land ones)?
Port hexes are water hexes.
private final void getAdjacentHexes_AddIfOK(java.util.Vector<java.lang.Integer> addTo, boolean includeWater, int hexCoord, int d1, int d2)
addTo
- the list we're building of hexes that touch this hex, as a Vector of Integer coordinates.includeWater
- Should water hexes be returned (not only land ones)?
Port hexes are water hexes.hexCoord
- Coordinate ("ID") of this hexd1
- Delta along axis 1d2
- Delta along axis 2public int getAdjacentNodeToHex(int hexCoord, int dir) throws java.lang.IllegalArgumentException
hexCoord
- Coordinate ("ID") of this hexdir
- Direction, clockwise from top (northern point of hex):
0 is north, 1 is northeast, etc, 5 is northwest.
java.lang.IllegalArgumentException
- if dir < 0 or dir > 5public int[] getAdjacentNodesToHex(int hexCoord)
hexCoord
- Coordinate of this hex
getAdjacentNodeToHex(int, int)
public int getAdjacentHexToEdge(int edgeCoord, int facing) throws java.lang.IllegalArgumentException
edgeCoord
- The edge's coordinate. maxEdge
is 0xCC in v1 and v2 encoding.facing
- Facing from edge; 1 to 6.
This will be either a direction perpendicular to the edge,
or towards one end. Each end has two facing directions angled
towards it; both will return the same hex.
Facing 2 is FACING_E
, 3 is FACING_SE
, 4 is SW, etc.
java.lang.IllegalArgumentException
- if facing < 1 or facing > 6public SOCPlayingPiece settlementAtNode(int nodeCoord)
nodeCoord
- Location coordinate (as returned by SOCBoardPanel.findNode)
public SOCRoad roadAtEdge(int edgeCoord)
edgeCoord
- Location coordinate (as returned by SOCBoardPanel.findEdge)
SOCPlayingPiece.getType()
or SOCRoad.isRoadNotShip()
to determine the returned piece type.
At most one road or ship can be placed at any one edge.public boolean isNodeOnLand(int node)
node
- Node coordinate
public java.lang.String nodeCoordToString(int node)
getAdjacentHexesToNode(int)
public java.lang.String edgeCoordToString(int edge)
getNumberOnHexFromCoord(int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |