org.jscience.computing.game.fourwins
Class FourWinsGame

java.lang.Object
  extended by org.jscience.computing.game.AbstractGame
      extended by org.jscience.computing.game.fourwins.FourWinsGame
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, GamePlay

public class FourWinsGame
extends AbstractGame

FourWinsGame represents the game of 4-wins or 4-connects. (other names for the game: four wins, connect four, vier gewinnt)

See Also:
Serialized Form

Field Summary
protected  int[][] board
          DOCUMENT ME!
 int boardHeight
          DOCUMENT ME!
 int boardWidth
          DOCUMENT ME!
 int MAX_MOVES
          DOCUMENT ME!
static int WINNING_LINE_LENGTH
          DOCUMENT ME!
 
Constructor Summary
FourWinsGame()
          creates the standard game board with 7x6
FourWinsGame(java.lang.String name)
          Creates a new FourWinsGame object.
FourWinsGame(java.lang.String name, int width, int height)
          Creates a new FourWinsGame object.
 
Method Summary
protected  int checkPositionWin(int column, int row)
          DOCUMENT ME!
 java.lang.Object clone()
          DOCUMENT ME!
 boolean equals(java.lang.Object obj)
          DOCUMENT ME!
protected  int freePositionInColumn(int column)
          DOCUMENT ME!
 int getHeight()
          DOCUMENT ME!
 int getValueAt(int column, int row)
          Returns the value for a specified position in the game board.
 int getWidth()
          DOCUMENT ME!
 int[] getWinner()
          DOCUMENT ME!
 int hashCode()
          experimental, but working
protected  GameMove[] listLegalMoves()
          DOCUMENT ME!
 int nextPlayer()
          DOCUMENT ME!
protected  boolean popMove()
          DOCUMENT ME!
protected  boolean pushMove(GameMove move)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class org.jscience.computing.game.AbstractGame
clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getRedoList, getResult, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

WINNING_LINE_LENGTH

public static final int WINNING_LINE_LENGTH
DOCUMENT ME!

See Also:
Constant Field Values

MAX_MOVES

public final int MAX_MOVES
DOCUMENT ME!


boardWidth

public final int boardWidth
DOCUMENT ME!


boardHeight

public final int boardHeight
DOCUMENT ME!


board

protected int[][] board
DOCUMENT ME!

Constructor Detail

FourWinsGame

public FourWinsGame()
creates the standard game board with 7x6


FourWinsGame

public FourWinsGame(java.lang.String name)
Creates a new FourWinsGame object.

Parameters:
name - DOCUMENT ME!

FourWinsGame

public FourWinsGame(java.lang.String name,
                    int width,
                    int height)
             throws java.lang.IllegalArgumentException
Creates a new FourWinsGame object.

Parameters:
name - DOCUMENT ME!
width - DOCUMENT ME!
height - DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!
Method Detail

listLegalMoves

protected GameMove[] listLegalMoves()
DOCUMENT ME!

Specified by:
listLegalMoves in class AbstractGame
Returns:
DOCUMENT ME!

nextPlayer

public int nextPlayer()
DOCUMENT ME!

Returns:
DOCUMENT ME!

popMove

protected boolean popMove()
DOCUMENT ME!

Specified by:
popMove in class AbstractGame
Returns:
DOCUMENT ME!

pushMove

protected boolean pushMove(GameMove move)
DOCUMENT ME!

Specified by:
pushMove in class AbstractGame
Parameters:
move - DOCUMENT ME!
Returns:
DOCUMENT ME!

getWinner

public int[] getWinner()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getValueAt

public int getValueAt(int column,
                      int row)
               throws java.lang.ArrayIndexOutOfBoundsException
Returns the value for a specified position in the game board. The parameters are directly used to retrieve the array elements; therefore, ArrayIndexOutOfBoundsException may be thrown

Parameters:
column - DOCUMENT ME!
row - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - DOCUMENT ME!

freePositionInColumn

protected int freePositionInColumn(int column)
                            throws java.lang.IllegalArgumentException
DOCUMENT ME!

Parameters:
column - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

checkPositionWin

protected int checkPositionWin(int column,
                               int row)
DOCUMENT ME!

Parameters:
column - DOCUMENT ME!
row - DOCUMENT ME!
Returns:
DOCUMENT ME!

getWidth

public int getWidth()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getHeight

public int getHeight()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class AbstractGame
Returns:
DOCUMENT ME!

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
DOCUMENT ME!

Specified by:
clone in interface GamePlay
Overrides:
clone in class AbstractGame
Returns:
DOCUMENT ME!
Throws:
java.lang.CloneNotSupportedException - DOCUMENT ME!
See Also:
AbstractGame.spawnChild(GameMove)

hashCode

public int hashCode()
experimental, but working

Overrides:
hashCode in class java.lang.Object
Returns:
DOCUMENT ME!

equals

public boolean equals(java.lang.Object obj)
DOCUMENT ME!

Overrides:
equals in class java.lang.Object
Parameters:
obj - DOCUMENT ME!
Returns:
DOCUMENT ME!