net.bluebones.tictactoe
Class Board

java.lang.Object
  extended by net.bluebones.tictactoe.Board

public class Board
extends Object

Methods that work on a tictactoe board. The board is represented as a byte[][] and worked on with static methods rather than being an object with behaviour so that AI players can have many many copies of boards in memory without making the memory requirements outrageous.

Version:
1.1
Author:
Thomas David Baker, bakert+tictactoe@gmail.com

Field Summary
static byte SIZE
          Size of one side of the board.
 
Constructor Summary
Board()
           
 
Method Summary
static byte[][] copy(byte[][] board)
          Makes a new copy of the specified board.
static boolean isEmpty(byte[][] board, Move move)
          Determines if the square the specified Move takes place in is empty or not.
static boolean isFull(byte[][] board)
          Determines if this board is full (no more moves possible) or not.
static boolean isWinner(byte[][] board, byte player)
          Determines if the specified player has won at the current board position.
static boolean placePiece(byte[][] board, Move m)
          Does the move specified in m on board.
static void printBoard(byte[][] board)
          Prints a graphical representation of the board to STDOUT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE

public static final byte SIZE
Size of one side of the board.

See Also:
Constant Field Values
Constructor Detail

Board

public Board()
Method Detail

isEmpty

public static boolean isEmpty(byte[][] board,
                              Move move)
Determines if the square the specified Move takes place in is empty or not.

Parameters:
move - Move to check position of.
Returns:
boolean, true if the square is empty.

isWinner

public static boolean isWinner(byte[][] board,
                               byte player)
Determines if the specified player has won at the current board position.

Parameters:
board - byte[][] board to check.
player - byte either TicTacToe.NOUGHTS or TicTacToe.CROSSES.
Returns:
boolean, true if the specified player has won.

placePiece

public static boolean placePiece(byte[][] board,
                                 Move m)
Does the move specified in m on board.

Parameters:
board - byte[][] of board to perform move on.
m - Move to perform.
Returns:
boolean of whether the move succeeded or not.
Throws:
IllegalStateException - If the move is not legal.

isFull

public static boolean isFull(byte[][] board)
Determines if this board is full (no more moves possible) or not.

Returns:
boolean, true if this board is full.

printBoard

public static void printBoard(byte[][] board)
Prints a graphical representation of the board to STDOUT.


copy

public static byte[][] copy(byte[][] board)
Makes a new copy of the specified board. This is a new object reference so changes to the original board will not affect it and vice versa.

Parameters:
board - byte[][] board to copy.
Returns:
byte[][] copy of board.