|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectsoc.game.SOCBoard
This is a representation of the board in Settlers of Catan.
Other methods to examine the board: SOCGame.getPlayersOnHex(int),
SOCGame.putPiece(SOCPlayingPiece), etc.
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. 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). Unfortunately this means the board can't be expanded without changing this encoding. The center hex is encoded as 77; see the dissertation appendix PDF for diagrams.
| Field Summary | |
private int[] |
boardNum2Num
Key to the numbers[] : 0 : 2 1 : 3 2 : 4 3 : 5 4 : 6 5 : 8 6 : 9 7 : 10 8 : 11 9 : 12 |
private java.util.Vector |
cities
cities on the board; Vector of SOCPlayingPiece |
static int |
CLAY_HEX
|
static int |
CLAY_PORT
Clay port type |
static int |
CLAY_PORT_HEX
|
static int |
DESERT_HEX
Desert; lowest-numbered hex type |
private int[] |
hexIDtoNum
translate hex ID to an array index |
private int[] |
hexLayout
Each element's value encodes port facing and hex type. |
private int[] |
hexNodes
offset to add to hex coord to get all node coords |
static int |
MAX_ROBBER_HEX
Highest-numbered hex type which may hold a robber: WOOD_HEX. |
static int |
MAXEDGE
largest coordinate value for an edge |
static int |
MAXHEX
largest coordinate value for a hex |
static int |
MAXNODE
largest coordinate value for a node |
static int |
MAXNODEPLUSONE
largest coordinate value for a node plus one |
static int |
MINEDGE
smallest coordinate value for an edge |
static int |
MINHEX
smallest coordinate value for a hex |
static int |
MINNODE
smallest coordinate value for a node |
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 |
protected java.util.Hashtable |
nodesOnBoard
a list of nodes on the board; key is node's Integer coordinate, value is Boolean |
private int[] |
nodeToHex
offset of all hexes adjacent to a node |
private int[] |
num2BoardNum
|
private int[] |
numberLayout
Dice number from hex numbers; @see #numToHexID |
private int[] |
numToHexID
Hex coordinates from hex numbers |
static int |
ORE_HEX
|
static int |
ORE_PORT
Ore port type |
static int |
ORE_PORT_HEX
|
private java.util.Vector |
pieces
pieces on the board; Vector of SOCPlayingPiece |
private java.util.Vector[] |
ports
where the ports are; coordinates per port type. |
private java.util.Random |
rand
random number generator |
private java.util.Vector |
roads
roads on the board; Vector of SOCPlayingPiece |
private int |
robberHex
the hex coordinate that the robber is in; placed on desert in constructor |
private java.util.Vector |
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; higher-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; highest-numbered land hex type (also MAX_ROBBER_HEX) |
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 | |
SOCBoard()
Create a new Settlers of Catan Board |
|
| Method Summary | |
java.lang.String |
edgeCoordToString(int edge)
|
static java.util.Vector |
getAdjacentEdgesToEdge(int coord)
|
static java.util.Vector |
getAdjacentEdgesToNode(int coord)
|
static java.util.Vector |
getAdjacentHexesToNode(int coord)
|
static java.util.Vector |
getAdjacentNodesToEdge(int coord)
|
static java.util.Vector |
getAdjacentNodesToNode(int coord)
|
java.util.Vector |
getCities()
get the list of cities |
int[] |
getHexLayout()
|
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[] |
getNumberLayout()
|
int |
getNumberOnHexFromCoord(int hex)
Given a hex coordinate, return the number on that hex |
int |
getNumberOnHexFromNumber(int hex)
Given a hex number, return the (dice-roll) number on that hex |
java.util.Vector |
getPieces()
get the list of pieces on the board |
java.util.Vector |
getPortCoordinates(int portType)
|
int |
getPortTypeFromHex(int hex)
|
java.util.Vector |
getRoads()
get the list of roads |
int |
getRobberHex()
|
java.util.Vector |
getSettlements()
get the list of settlements |
private void |
initHexIDtoNumAux(int begin,
int end,
int num)
Auxiliary method for initializing part of the hexIDtoNum array |
boolean |
isNodeOnBoard(int node)
|
void |
makeNewBoard()
Shuffle the hex tiles and layout a board |
java.lang.String |
nodeCoordToString(int node)
|
private void |
placePort(int port,
int hex,
int face)
Auxiliary method for placing the port hexes |
void |
putPiece(SOCPlayingPiece pp)
put a piece on the board |
void |
removePiece(SOCPlayingPiece piece)
remove a piece from the board |
SOCPlayingPiece |
roadAtEdge(int edgeCoord)
If there's a road placed at this node, find it. |
void |
setHexLayout(int[] hl)
set the hexLayout |
void |
setNumberLayout(int[] nl)
set the number layout |
void |
setRobberHex(int rh)
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 |
public static final int DESERT_HEX
public static final int CLAY_HEX
public static final int ORE_HEX
public static final int SHEEP_HEX
public static final int WHEAT_HEX
public static final int WOOD_HEX
public static final int WATER_HEX
public 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
public static final int CLAY_PORT
public static final int ORE_PORT
public static final int SHEEP_PORT
public static final int WHEAT_PORT
public static final int WOOD_PORT
public static final int MAX_ROBBER_HEX
WOOD_HEX.
public static final int MAXHEX
public static final int MINHEX
public static final int MAXEDGE
public static final int MINEDGE
public static final int MAXNODE
public static final int MINNODE
public static final int MAXNODEPLUSONE
private int[] hexLayout
(port facing) (kind of port)
\--> [0 0 0][0 0 0 0] <--/
kind of port:
1 : clay CLAY_PORT
2 : ore ORE_PORT
3 : sheep SHEEP_PORT
4 : wheat WHEAT_PORT
5 : wood WOOD_PORT
port facing:
6___ ___1
\/\/
/ \
5___| |___2
| |
\ /
4___/\/\___3
getHexTypeFromNumber(int)private int[] boardNum2Num
private int[] num2BoardNum
private int[] numberLayout
private int[] numToHexID
private int[] hexIDtoNum
private int[] hexNodes
private int[] nodeToHex
private int robberHex
private java.util.Vector[] ports
MISC_PORT to WOOD_PORT.
private java.util.Vector pieces
private java.util.Vector roads
private java.util.Vector settlements
private java.util.Vector cities
private java.util.Random rand
protected java.util.Hashtable nodesOnBoard
| Constructor Detail |
public SOCBoard()
| Method Detail |
private final void initHexIDtoNumAux(int begin,
int end,
int num)
begin - Beginning of coordinate rangeend - Ending coordinatenum - Number to assign to hexIDtoNum[] within this coordinate rangepublic void makeNewBoard()
private final void placePort(int port,
int hex,
int face)
port - Port type; in range MISC_PORT to WOOD_PORT.hex - Hex coordinateface - Facing of port; 1 to 6public int[] getHexLayout()
public int[] getNumberLayout()
public int getRobberHex()
public void setHexLayout(int[] hl)
hl - the hex layoutpublic int getPortTypeFromHex(int hex)
hex - the hex type, as in hexLayout
MISC_PORT to WOOD_PORTpublic void setNumberLayout(int[] nl)
nl - the number layoutpublic void setRobberHex(int rh)
rh - the robber hex coordinatepublic java.util.Vector getPortCoordinates(int portType)
portType - the type of port;
in range MISC_PORT to WOOD_PORT.
public int getNumberOnHexFromCoord(int hex)
hex - the coordinates for a hex
public int getNumberOnHexFromNumber(int hex)
hex - the number of a hex
public int getHexTypeFromCoord(int hex)
hex - the coordinates for a hex
CLAY_PORT_HEX to WOOD_PORT_HEX,
DESERT_HEX, or MISC_PORT_HEX for any port.public int getHexTypeFromNumber(int hex)
hex - the number of a hex (not its coordinate)
CLAY_PORT_HEX to WOOD_PORT_HEX,
DESERT_HEX, or MISC_PORT_HEX for any port.public void putPiece(SOCPlayingPiece pp)
public void removePiece(SOCPlayingPiece piece)
public java.util.Vector getPieces()
public java.util.Vector getRoads()
public java.util.Vector getSettlements()
public java.util.Vector getCities()
public static java.util.Vector getAdjacentNodesToEdge(int coord)
public static java.util.Vector getAdjacentEdgesToEdge(int coord)
public static java.util.Vector getAdjacentHexesToNode(int coord)
public static java.util.Vector getAdjacentEdgesToNode(int coord)
public static java.util.Vector getAdjacentNodesToNode(int coord)
public SOCPlayingPiece settlementAtNode(int nodeCoord)
nodeCoord - Location coordinate (as returned by SOCBoardPanel.findNode)
public SOCPlayingPiece roadAtEdge(int edgeCoord)
edgeCoord - Location coordinate (as returned by SOCBoardPanel.findEdge)
public boolean isNodeOnBoard(int node)
node - Node coordinate
public java.lang.String nodeCoordToString(int node)
public java.lang.String edgeCoordToString(int edge)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||