knockabout.gamemodel
Class Board

java.lang.Object
  extended byknockabout.gamemodel.Board

public class Board
extends java.lang.Object

The Knockabout GameBoard main data struct is simply of a double-array of Hexes. Due to the shape of the board (see game pics on website), not every element in the array represents a valid board position. We can use the isValidCoord method to verify that an (x,y) position on the gameboard is valid. uses the coordinate system as depicted on http://www.gamerz.net/pbmserv/hexxagon.html I say we scrap the use of letters and start at 0 on each side. With x's on the left and y's on the topright as so (o's represent the gutter):

0 1 2 3 4 5 6
/ / / / / / / 7
0- o o o o o o o / 8 y
1- o . . . . . . o / 9
x 2- o . . . . . . . o / 10
3- o . . . . . . . . o / 11
4- o . . . . . . . . . o / 12
5- o . . . . . . . . . . o /
6- o . . . . . . . . . . . o
7- o . . . . . . . . z . o <--- that 'z' is at loc (x,y) = (7,10)
8- o . . . . . . . . . o
9- o . . . . . . . . o
10- o . . . . . . . o
11- o . . . . . . o
12- o o o o o o o


- mutable data type
- the starting position is as follows:
initial face-up values:
all four-sided dice: 1
all six-sided dice: 2
all eight-sided dice: 3
positions:
(3,4) black d4
(3,5) yellow d4
(4,3) black d6
(4,7) yellow d6
(5,2) black d8
(5,5) black d4
(5,6) yellow d4
(5,9) yellow d8
(6,4) black d6)
(6,8) yellow d6
(7,3) black d8
(7,6) black d4
(7,7) yellow d4
(7,10) yellow d8
(8,5) black d6
(8,9) yellow d6
(9,7) black d4
(9,8) yellow d4


Field Summary
static int BOARDSIZE
           
 
Constructor Summary
Board()
          New Instance of HexBoard (with dies at initial positions)
Board(java.util.List initialDies)
          New intance of HexBoard with specified initial condition
 
Method Summary
 Board deepclone()
          Performs a deep clone of the board, including all underlying fields
protected  void empty()
          Remove all dies from the board (not just put them in the gutter..
 java.util.List getBlackDies()
           
 Hex getHex(int x, int y)
          Returns the Hexagon located at Board coordinate (x,y).
 java.util.List getPieces(int color)
          Access all the pieces of a given color
 java.util.List getPiecesNotInGutter(int color)
          Get all the dies of a given color that are not in the gutter
 int getRemainingBlackD4()
           
 int getRemainingBlackD6()
           
 int getRemainingBlackD8()
           
 int getRemainingBlackDies()
           
 int getRemainingYellowD4()
           
 int getRemainingYellowD6()
           
 int getRemainingYellowD8()
           
 int getRemainingYellowDies()
           
 java.util.List getYellowDies()
           
static boolean inGutter(int x, int y)
          Is position (x,y) located in the Gutter area?
static boolean isValidCoord(int x, int y)
          Is this (x,y) coordinate located on the Hex-Grid
protected  boolean isValidGutterMove(int x, int y, int dir)
           
protected  boolean isValidGutterMove(Move m)
           
 boolean isValidMove(Move move, int playercolor)
          Returns true if the given move by black or yellow player is a legal move, otherwise false
 void move(int x1, int y1, int x2, int y2)
          Moves a die from one hex at (x1,y1) to the position (x2,y2), updating all required fields
static int nextDir(int x, int y, int dir)
           
static int nextX(int x, int dir)
           
static int nextY(int y, int dir)
           
protected  void reloadWithDies(java.util.List dies)
           
protected  void setBlackDies(java.util.List set)
           
protected  void setRemainingBlackD4(int i)
           
protected  void setRemainingBlackD6(int i)
           
protected  void setRemainingBlackD8(int i)
           
protected  void setRemainingBlackDies(int i)
           
protected  void setRemainingYellowD4(int i)
           
protected  void setRemainingYellowD6(int i)
           
protected  void setRemainingYellowD8(int i)
           
protected  void setRemainingYellowDies(int i)
           
protected  void setYellowDies(java.util.List set)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOARDSIZE

public static final int BOARDSIZE
See Also:
Constant Field Values
Constructor Detail

Board

public Board(java.util.List initialDies)
New intance of HexBoard with specified initial condition

Parameters:
initialDies - A list of Dies object with initial information

Board

public Board()
New Instance of HexBoard (with dies at initial positions)

Method Detail

empty

protected void empty()
Remove all dies from the board (not just put them in the gutter.. they really "disappear")


reloadWithDies

protected void reloadWithDies(java.util.List dies)
Parameters:
dies -

inGutter

public static boolean inGutter(int x,
                               int y)
Is position (x,y) located in the Gutter area?

Returns:

isValidCoord

public static boolean isValidCoord(int x,
                                   int y)
Is this (x,y) coordinate located on the Hex-Grid

Parameters:
x -
y -

move

public void move(int x1,
                 int y1,
                 int x2,
                 int y2)
Moves a die from one hex at (x1,y1) to the position (x2,y2), updating all required fields


isValidMove

public boolean isValidMove(Move move,
                           int playercolor)
Returns true if the given move by black or yellow player is a legal move, otherwise false


isValidGutterMove

protected boolean isValidGutterMove(Move m)

isValidGutterMove

protected boolean isValidGutterMove(int x,
                                    int y,
                                    int dir)

getHex

public Hex getHex(int x,
                  int y)
Returns the Hexagon located at Board coordinate (x,y). If there is no Hexagon (i.e. it is not a legal board position), it will return null.


nextX

public static int nextX(int x,
                        int dir)

nextY

public static int nextY(int y,
                        int dir)

nextDir

public static int nextDir(int x,
                          int y,
                          int dir)

deepclone

public Board deepclone()
Performs a deep clone of the board, including all underlying fields


getPieces

public java.util.List getPieces(int color)
Access all the pieces of a given color

Parameters:
color - The color code (see Player class)
Returns:
A list of Die objects

getPiecesNotInGutter

public java.util.List getPiecesNotInGutter(int color)
Get all the dies of a given color that are not in the gutter

Parameters:
color - The color code (see Player class)
Returns:
A list of Die objects

getBlackDies

public java.util.List getBlackDies()
Returns:

getYellowDies

public java.util.List getYellowDies()
Returns:

setBlackDies

protected void setBlackDies(java.util.List set)
Parameters:
set -

setYellowDies

protected void setYellowDies(java.util.List set)
Parameters:
set -

getRemainingBlackDies

public int getRemainingBlackDies()
Returns:

getRemainingYellowDies

public int getRemainingYellowDies()
Returns:

setRemainingBlackDies

protected void setRemainingBlackDies(int i)
Parameters:
i -

setRemainingYellowDies

protected void setRemainingYellowDies(int i)
Parameters:
i -

toString

public java.lang.String toString()

getRemainingBlackD4

public int getRemainingBlackD4()
Returns:

getRemainingBlackD6

public int getRemainingBlackD6()
Returns:

getRemainingBlackD8

public int getRemainingBlackD8()
Returns:

getRemainingYellowD4

public int getRemainingYellowD4()
Returns:

getRemainingYellowD6

public int getRemainingYellowD6()
Returns:

getRemainingYellowD8

public int getRemainingYellowD8()
Returns:

setRemainingBlackD4

protected void setRemainingBlackD4(int i)
Parameters:
i -

setRemainingBlackD6

protected void setRemainingBlackD6(int i)
Parameters:
i -

setRemainingBlackD8

protected void setRemainingBlackD8(int i)
Parameters:
i -

setRemainingYellowD4

protected void setRemainingYellowD4(int i)
Parameters:
i -

setRemainingYellowD6

protected void setRemainingYellowD6(int i)
Parameters:
i -

setRemainingYellowD8

protected void setRemainingYellowD8(int i)
Parameters:
i -