Connect four in JAVA?!?
/**
*
* A 'Connect 4' board object represents the game board of
* the 'Connect 4' game. It consists of an 8 x 8 grid of
* spaces, where each space can contain either a red checker,
* a black checker, or no checker. The board can be thought
* of as being vertical, so checkers fill the grid squares
* from the bottom up.
*/
public interface Connect4Board
{
final static public int RED = -1;
final static public int NONE = 0;
final static public int BLACK = 1;
/**
* This method will clear the board's grid so that all spaces
* are marked as having 'no checker' in each space.
*/
public void clear();
/**
* This method adds a red checker to the specified column, if
* possible. (If this column is full, nothing happens.) If
* there is space in the column for another checker, then
* a red checker will be placed in the lowest unoccupied
* space in the column.
*
* Column 0 corresponds to the left side of the grid.
*
* @param column A column number, from 0 to 7.
*/
public void addRedChecker (int column);
/**
* This method adds a black checker to the specified column, if
* possible. (If this column is full, nothing happens.) If
* there is space in the column for another checker, then
* a black checker will be placed in the lowest unoccupied
* space in the column.
* <p>
*
* Column 0 corresponds to the left side of the grid.
*
* @param column A column number, from 0 to 7.
*/
public void addBlackChecker (int column);
/**
* This method removes the topmost checker from the specified
* column. If the column is empty, nothing happens.
*
* Column 0 corresponds to the left side of the grid.
*
* @param column A column number, from 0 to 7.
*/
public void removeChecker (int column);
/**
* Returns true if the board is full of checkers.
*
* @return true if the board is full of checkers.
*/
public boolean isFull ();
/**
* Returns an integer describing the checker in the specified
* space in the grid. Row 0 corresponds to the bottom
* of the grid, column 0 corresponds to the left side of the grid.
* <p>
*
* Returns the RED constant (defined above) if the space has
* a red checker in it, the BLACK constant (defined above) if the
* space has a black checker in it, and NONE (defined above) if
* there is no checker in the space.
* <p>
*
* If the row or column number is outside the range 0..7, this
* method will return NONE (defined above).
*
* @param row A row number, from 0 to 7.
* @param column A column number, from 0 to 7.
* @return An integer that describes the contents of the space.
*/
public int getSpaceContents (int row, int column);
/**
* Returns true if the board has four red checkers together in a row,
* column, or diagonal line. This would indicate a win for red.
*
* @return True if there are four red checkers in a line.
*/
public boolean redHasWon ();
/**
* Returns true if the board has four black checkers together in a row,
* column, or diagonal line. This would indicate a win for black.
*
* @return True if there are four black checkers in a line.
*/
public boolean blackHasWon ();
/**
* @return An integer that describes the winning color, if any.
*/
public int getWinner ();
}
|