pushers
Class PBoard

java.lang.Object
  extended by boardgame.Board
      extended by pushers.PBoard
All Implemented Interfaces:
java.lang.Cloneable

public class PBoard
extends Board

Pushers board representation. The board is represented as a one dimensional array with a coord in the i-th row and j-th column at index (i-1) * SIZE + (j-1).


Field Summary
static int BLACK
           
static int BLACK_PUSHER
           
protected  int[] data
           
static int EMPTY
           
static int MAX_TURNS
          Maximum number of turns before a draw.
protected  int[] numPusheePieces
           
protected  int[] numPusherPieces
           
static int PUSHER
           
static int SIZE
          Board size
protected  int turn
           
protected  int turnCount
           
static int WHITE
           
static int WHITE_PUSHER
           
protected  int winner
           
 
Fields inherited from class boardgame.Board
BOARD, DRAW, NOBODY
 
Constructor Summary
PBoard()
          Returns a board in the starting position.
PBoard(PBoard bb)
          Returns a deep copy of another board.
 
Method Summary
 java.lang.Object clone()
          Return a copy of this board
 BoardPanel createBoardPanel()
          Return a custom BoardPanel so that we can accept user input
 void forceWinner(int win)
          Set a winner without finishing the game.
 int[] getBoardData()
          Get the array containing the board data directly
 int getCol(int coord)
           
 int getCoord(int row, int col)
          Convert between array index and (row,col) pairs
 int getIDForName(java.lang.String s)
          Get the player ID corresponding to name
 java.lang.String getNameForID(int p)
          Get the name corresponding to a player ID.
 int getNumberOfPlayers()
          Get the number of players.
 int getNumPusheePieces(int playerID)
          Return the number of pushee pieces for a player.
 int getNumPusherPieces(int playerID)
          Return the number of pusher pieces for a player.
 int getPieceAt(int index)
          Get the value at a position: return BLACK, WHITE or EMPTY.
 int getPieceAt(int row, int col)
           
 int getRow(int coord)
           
 int getTurn()
          Return the next player.
 int getTurnsPlayed()
          Get the number of turns played.
 int getWinner()
          Return winner colour, DRAW or NOBODY if no winner yet.
 boolean isLegal(int player, int orig, int dest)
          Verify legality of a move.
 boolean isLegal(Move mm)
          Verify legality of a move.
 void move(int player, int orig, int dest)
          Execute a move.
 void move(Move mm)
          Execute a move.
 void moveFast(int player, int orig, int dest)
          Execute a move without checking legality.
 Move parseMove(java.lang.String str)
          Parse a move from a string
 java.lang.String toString()
          String representation of a board
 
Methods inherited from class boardgame.Board
filterMove, getBoardMove
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIZE

public static final int SIZE
Board size

See Also:
Constant Field Values

MAX_TURNS

public static final int MAX_TURNS
Maximum number of turns before a draw.

See Also:
Constant Field Values

EMPTY

public static final int EMPTY
See Also:
Constant Field Values

WHITE

public static final int WHITE
See Also:
Constant Field Values

BLACK

public static final int BLACK
See Also:
Constant Field Values

WHITE_PUSHER

public static final int WHITE_PUSHER
See Also:
Constant Field Values

BLACK_PUSHER

public static final int BLACK_PUSHER
See Also:
Constant Field Values

PUSHER

public static final int PUSHER
See Also:
Constant Field Values

data

protected final int[] data

turn

protected int turn

winner

protected int winner

turnCount

protected int turnCount

numPusherPieces

protected int[] numPusherPieces

numPusheePieces

protected int[] numPusheePieces
Constructor Detail

PBoard

public PBoard()
Returns a board in the starting position.


PBoard

public PBoard(PBoard bb)
Returns a deep copy of another board.

Method Detail

getBoardData

public int[] getBoardData()
Get the array containing the board data directly


getPieceAt

public int getPieceAt(int index)
Get the value at a position: return BLACK, WHITE or EMPTY. This used 0-based coordinates.


getPieceAt

public int getPieceAt(int row,
                      int col)

getCoord

public int getCoord(int row,
                    int col)
Convert between array index and (row,col) pairs


getRow

public int getRow(int coord)

getCol

public int getCol(int coord)

getNumPusherPieces

public int getNumPusherPieces(int playerID)
Return the number of pusher pieces for a player.


getNumPusheePieces

public int getNumPusheePieces(int playerID)
Return the number of pushee pieces for a player.


getWinner

public int getWinner()
Return winner colour, DRAW or NOBODY if no winner yet.

Specified by:
getWinner in class Board

forceWinner

public void forceWinner(int win)
Set a winner without finishing the game.

Specified by:
forceWinner in class Board

getTurn

public int getTurn()
Return the next player.

Specified by:
getTurn in class Board

getTurnsPlayed

public int getTurnsPlayed()
Get the number of turns played.

Specified by:
getTurnsPlayed in class Board

isLegal

public boolean isLegal(Move mm)
Verify legality of a move. This depends on the current turn.


isLegal

public boolean isLegal(int player,
                       int orig,
                       int dest)
Verify legality of a move. This depends on the current turn.


move

public void move(Move mm)
          throws java.lang.IllegalArgumentException
Execute a move.

Specified by:
move in class Board
Throws:
java.lang.IllegalArgumentException

move

public void move(int player,
                 int orig,
                 int dest)
          throws java.lang.IllegalArgumentException
Execute a move.

Throws:
java.lang.IllegalArgumentException

moveFast

public void moveFast(int player,
                     int orig,
                     int dest)
Execute a move without checking legality.


clone

public java.lang.Object clone()
Return a copy of this board

Specified by:
clone in class Board

toString

public java.lang.String toString()
String representation of a board

Overrides:
toString in class java.lang.Object

getNameForID

public java.lang.String getNameForID(int p)
Description copied from class: Board
Get the name corresponding to a player ID. This function should also return an appropriate string for the value Board.BOARD if the board actions mechanism is used.

Specified by:
getNameForID in class Board

getIDForName

public int getIDForName(java.lang.String s)
Description copied from class: Board
Get the player ID corresponding to name

Specified by:
getIDForName in class Board

getNumberOfPlayers

public int getNumberOfPlayers()
Description copied from class: Board
Get the number of players. This must correspond to the number of player IDs!

Specified by:
getNumberOfPlayers in class Board

parseMove

public Move parseMove(java.lang.String str)
               throws java.lang.NumberFormatException,
                      java.lang.IllegalArgumentException
Description copied from class: Board
Parse a move from a string

Specified by:
parseMove in class Board
Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException

createBoardPanel

public BoardPanel createBoardPanel()
Return a custom BoardPanel so that we can accept user input

Overrides:
createBoardPanel in class Board