com.anji.ttt
Interface Board

All Known Implementing Classes:
GomokuBoard, TttBoard

public interface Board

Abstracts the common elements of the playing area of a game, such as Tic-Tac-Toe or Checkers. The board is "squashed" into a 1-dimensional array of integers, referenced as the board state. Positions containing friendly pieces have value 1, opponent pieces -1, and empty spaces 0.

Author:
Derek James

Method Summary
 boolean checkForTie()
           
 boolean checkForWin()
           
 boolean checkLegalMove(int newMove)
           
 java.lang.String displayBoard()
           
 int getBoardSize()
           
 int[] getBoardState()
           
 void initializeBoard()
          set up board to initial state before game has started
 void swap()
          swap all friendly pieces for opponent and vice versa
 void updateBoard(int newMove)
          updates board state such that position newMove will now equal 1
 

Method Detail

getBoardSize

public int getBoardSize()
Returns:
number of spaces in a single row or column

initializeBoard

public void initializeBoard()
set up board to initial state before game has started


checkLegalMove

public boolean checkLegalMove(int newMove)
Parameters:
newMove - position in which to place next move
Returns:
false if newMove would create an invalid board state, true otherwise

updateBoard

public void updateBoard(int newMove)
updates board state such that position newMove will now equal 1

Parameters:
newMove - position in which to place next move; must be between >= 0 and < size of board

checkForWin

public boolean checkForWin()
Returns:
boolean true if state of board represents a win for friendly pieces (those with value 1), false otherwise

checkForTie

public boolean checkForTie()
Returns:
true if state of board represents a tie, false otherwise

displayBoard

public java.lang.String displayBoard()
Returns:
string representation of board

getBoardState

public int[] getBoardState()
Returns:
int[] representation of board; friendly pieces are 1, opponent -1, empty spaces 0

swap

public void swap()
swap all friendly pieces for opponent and vice versa