Class OthelloBoard

java.lang.Object
  extended by GameBoard
      extended by OthelloBoard
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class OthelloBoard
extends GameBoard
implements java.io.Serializable, java.lang.Cloneable

This class manages the data necessary for an Othello board.

Author:
Adam Hauer Stony Brook University
See Also:
Serialized Form

Field Summary
 
Fields inherited from class GameBoard
NOTHING, P1, P2
 
Constructor Summary
OthelloBoard()
          Constructor for starting a game with an empty board
 
Method Summary
 boolean checkAvailability()
          Examines the board for a given player and checks if there are any available moves to make for that player
 void chooseCell(int row, int col, int player)
          Method to allow a player to select a cell.
 OthelloBoard clone()
          Method for making a duplicate of the current configuration of the board
 int flipLeft(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going left
 int flipLow(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going down
 int flipLowerLeft(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going lower left
 int flipLowerRight(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going lower right
 int flipRight(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going right
 int flipUp(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going up
 int flipUpperLeft(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going upper left
 int flipUpperRight(int row, int col, int player)
          Recursive method to try and flip pieces of opposing player going upper right
 int getWinner()
          Determines who has won the game.
 boolean isLegalMove(java.awt.Dimension testMove)
          This method checks if the selected move is allowed by the current player
 void resetBoard()
          Method to reset the entire board, assigning all cells to have value of NOTHING.
 void skipTurn()
          Method for skipping the current player's turn
 
Methods inherited from class GameBoard
getCell, getTurn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OthelloBoard

public OthelloBoard()
Constructor for starting a game with an empty board

Method Detail

clone

public OthelloBoard clone()
Method for making a duplicate of the current configuration of the board

Overrides:
clone in class java.lang.Object
Returns:
- an Othello Board with the same exact configuration

chooseCell

public void chooseCell(int row,
                       int col,
                       int player)
Method to allow a player to select a cell. Makes the necessary changes to the game board as well. Also changes the turn so the next player can place a disc

Specified by:
chooseCell in class GameBoard
Parameters:
row - - row of the chosen cell
col - - column of the chosen cell
player - - the player who is making this move

checkAvailability

public boolean checkAvailability()
Examines the board for a given player and checks if there are any available moves to make for that player

Parameters:
- - player - the player that is being analyzed
Returns:
- TRUE if there are moves to make. FALSE if there are none.

flipUpperLeft

public int flipUpperLeft(int row,
                         int col,
                         int player)
Recursive method to try and flip pieces of opposing player going upper left

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipUp

public int flipUp(int row,
                  int col,
                  int player)
Recursive method to try and flip pieces of opposing player going up

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipUpperRight

public int flipUpperRight(int row,
                          int col,
                          int player)
Recursive method to try and flip pieces of opposing player going upper right

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipRight

public int flipRight(int row,
                     int col,
                     int player)
Recursive method to try and flip pieces of opposing player going right

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipLowerRight

public int flipLowerRight(int row,
                          int col,
                          int player)
Recursive method to try and flip pieces of opposing player going lower right

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipLow

public int flipLow(int row,
                   int col,
                   int player)
Recursive method to try and flip pieces of opposing player going down

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipLowerLeft

public int flipLowerLeft(int row,
                         int col,
                         int player)
Recursive method to try and flip pieces of opposing player going lower left

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

flipLeft

public int flipLeft(int row,
                    int col,
                    int player)
Recursive method to try and flip pieces of opposing player going left

Parameters:
row - - row of the disc
col - - column of the disc
player - - the player who is trying to flip
Returns:
- 1 if successful, 0 if not

isLegalMove

public boolean isLegalMove(java.awt.Dimension testMove)
This method checks if the selected move is allowed by the current player

Specified by:
isLegalMove in class GameBoard
Parameters:
testMove - - the row/column of the move being queried
Returns:
- TRUE if legal and FALSE if not.

getWinner

public int getWinner()
Determines who has won the game.

Specified by:
getWinner in class GameBoard
Returns:
- B if black has won, W if white has won, NOTHING if a tie

skipTurn

public void skipTurn()
Method for skipping the current player's turn

Overrides:
skipTurn in class GameBoard

resetBoard

public void resetBoard()
Method to reset the entire board, assigning all cells to have value of NOTHING.

Specified by:
resetBoard in class GameBoard