com.anji.gomoku
Class GomokuBoard

java.lang.Object
  extended by com.anji.gomoku.GomokuBoard
All Implemented Interfaces:
Board

public class GomokuBoard
extends java.lang.Object
implements Board

Represents the playing area of Gomoku.

Author:
Derek James

Constructor Summary
GomokuBoard(int aSize)
          Initialize board to be a square with each side of length aSize
 
Method Summary
 boolean checkForTie()
           
 boolean checkForWin()
           
 boolean checkLegalMove(int newMove)
          Return true if position newMove is empty, false otherwise.
 java.lang.String displayBoard()
           
 int getBoardSize()
           
 int[] getBoardState()
           
 void initializeBoard()
          initialize all positions to empty.
 void swap()
          swap all friendly pieces for opponent and vice versa
 void updateBoard(int newMove)
          Place friendly piece in position newMove in array boardState.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GomokuBoard

public GomokuBoard(int aSize)
Initialize board to be a square with each side of length aSize

Parameters:
aSize -
Method Detail

getBoardSize

public int getBoardSize()
Specified by:
getBoardSize in interface Board
Returns:
number of spaces in a single row or column
See Also:
Board.getBoardSize()

initializeBoard

public void initializeBoard()
initialize all positions to empty.

Specified by:
initializeBoard in interface Board
See Also:
Board.initializeBoard()

checkLegalMove

public boolean checkLegalMove(int newMove)
Return true if position newMove is empty, false otherwise.

Specified by:
checkLegalMove in interface Board
Parameters:
newMove - position in which to place next move
Returns:
false if newMove would create an invalid board state, true otherwise
See Also:
Board.checkLegalMove(int)

updateBoard

public void updateBoard(int newMove)
Place friendly piece in position newMove in array boardState.

Specified by:
updateBoard in interface Board
Parameters:
newMove - position in which to place next move; must be between >= 0 and < size of board
See Also:
Board.updateBoard(int)

checkForWin

public boolean checkForWin()
Specified by:
checkForWin in interface Board
Returns:
boolean true if board contains 5 1s in a row, horizontal, vertical, or diagonal; false otherwise
See Also:
Board.checkForWin()

checkForTie

public boolean checkForTie()
Specified by:
checkForTie in interface Board
Returns:
boolean true if board contains no empty spaces
See Also:
Board.checkForTie()

displayBoard

public java.lang.String displayBoard()
Specified by:
displayBoard in interface Board
Returns:
string representation of board
See Also:
Board.displayBoard()

getBoardState

public int[] getBoardState()
Specified by:
getBoardState in interface Board
Returns:
int[] representation of board; friendly pieces are 1, opponent -1, empty spaces 0
See Also:
Board.getBoardState()

swap

public void swap()
Description copied from interface: Board
swap all friendly pieces for opponent and vice versa

Specified by:
swap in interface Board
See Also:
Board.swap()