com.anji.ttt
Class TttBoard

java.lang.Object
  extended by com.anji.ttt.TttBoard
All Implemented Interfaces:
Board

public class TttBoard
extends java.lang.Object
implements Board

Tic-Tac-Toe board.

Author:
Derek James

Constructor Summary
TttBoard()
           
 
Method Summary
 boolean checkForTie()
           
 boolean checkForWin()
           
 boolean checkLegalMove(int newMove)
           
 java.lang.String displayBoard()
           
 int getBoardSize()
           
 int[] getBoardState()
           
 void initializeBoard()
          initialize board with all empty spaces
 void swap()
          swap all friendly pieces for opponent and vice versa
 void updateBoard(int newMove)
          Places friendly piece on boardState at position newMove.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TttBoard

public TttBoard()
Method Detail

initializeBoard

public void initializeBoard()
initialize board with all empty spaces

Specified by:
initializeBoard in interface Board

checkLegalMove

public boolean checkLegalMove(int newMove)
Specified by:
checkLegalMove in interface Board
Parameters:
newMove -
Returns:
boolean true iff newMove is an empty space

updateBoard

public void updateBoard(int newMove)
Places friendly piece on boardState at position newMove.

Specified by:
updateBoard in interface Board
Parameters:
newMove -

checkForWin

public boolean checkForWin()
Specified by:
checkForWin in interface Board
Returns:
boolean true if there exists 3 friendly pieces in a row

checkForTie

public boolean checkForTie()
Specified by:
checkForTie in interface Board
Returns:
boolean true if board is full and neither subject has won

displayBoard

public java.lang.String displayBoard()
Specified by:
displayBoard in interface Board
Returns:
String representation of boardState

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()

getBoardSize

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