Class Board

java.lang.Object
  |
  +--Board

public class Board
extends java.lang.Object

The Board class represents the 3 by 3 grid on which players make their marks in the game Tic Tac Toe. Bugs: none known


Constructor Summary
Board()
          Constructs a 3 by 3 grid with empty cells for the playing board.
 
Method Summary
 boolean cellFree(Move move)
          Checks if the cell is empty at the location of a specified move.
 boolean checkCol(int col, Mark mark)
          Checks for "three in a row", for a specified column and mark.
 boolean checkDiag(int diag, Mark mark)
          Checks for "three in a row", for a specified diagonal and mark.
 boolean checkRow(int row, Mark mark)
          Checks for "three in a row", for a specified row and mark.
 void display()
          Displays the board in the console window.
 void markMove(Move move, Mark mark)
          Puts a player's mark in the cell corresponding to the specified move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Board

public Board()
Constructs a 3 by 3 grid with empty cells for the playing board.
Method Detail

markMove

public void markMove(Move move,
                     Mark mark)
Puts a player's mark in the cell corresponding to the specified move.
Parameters:
move - the specified move (i.e. row and column coordinates)
mark - the player's mark to be made on the board, typically "X" or "O"

display

public void display()
Displays the board in the console window. Assumption: a player's mark is a single character.

cellFree

public boolean cellFree(Move move)
Checks if the cell is empty at the location of a specified move.
Parameters:
move - the specified move (i.e. row and column coordinates)
Returns:
returns true if the cell is empty at the location specified by move, otherwise false is returned

checkRow

public boolean checkRow(int row,
                        Mark mark)
Checks for "three in a row", for a specified row and mark.
Parameters:
row - the row specified to be checked, must be 1, 2, or 3
mark - the mark specified to be matched
Returns:
true if all cells in the specified row have the specified mark, otherwise false is returned

checkCol

public boolean checkCol(int col,
                        Mark mark)
Checks for "three in a row", for a specified column and mark.
Parameters:
col - the column specified to be checked, must be 1, 2, or 3
mark - the mark specified to be matched
Returns:
true if all cells in the specified column have the specified mark, otherwise false is returned

checkDiag

public boolean checkDiag(int diag,
                         Mark mark)
Checks for "three in a row", for a specified diagonal and mark.
Parameters:
diag - the diagonal specified to be checked, must be 1 or 2 1 is the diagonal from upper-left to lower-right 2 is the diagonal from upper-right to lower-left
mark - the mark specified to be matched
Returns:
true if all cells in the specified diagonal have the specified mark, otherwise false is returned