org.jscience.computing.game.wolfsheep
Class WolfsheepGame

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

public class WolfsheepGame
extends AbstractGame

an implementation of the wolf&sheep game which is played on a chess-like board; it uses the BoardPosition from the chess package for convenience. The game is played with 1 'wolf' and 4 'sheeps'; the setup and rules are somewhat simillar to checker, but way simpler. Wolf and sheeps start on opposite sites of the board. The sheeps can only move forward diagonal; the wolf can move back&forth, but only diagonal, also. Hence, each sheep has 2 move option at most and the wolf has 4 move options at most. The sheeps' goal is to contain the wolf, so that it cannot move anymore. The wolf's goal is to bypass the sheeps closing line and reach the other side of the board. If the wolf moves first, the wolf represents game role 0 and the sheeps represent 1. If the sheeps move first, these game roles are reversed.

See Also:
BoardPosition, Serialized Form

Field Summary
static byte SHEEP
          DOCUMENT ME!
static byte WOLF
          DOCUMENT ME!
 
Constructor Summary
WolfsheepGame()
          initiates the game with the wolf being the first player
WolfsheepGame(byte firstPlayer)
          can initiate the game with either the wolf or the sheeps as the first player;
 
Method Summary
 java.lang.Object clone()
          DOCUMENT ME!
 boolean equals(java.lang.Object obj)
          DOCUMENT ME!
 BoardPosition getSheepPosition(int index)
          accepts index 0 - 3
 int[] getWinner()
          DOCUMENT ME!
 BoardPosition getWolfPosition()
          DOCUMENT ME!
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, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SHEEP

public static final byte SHEEP
DOCUMENT ME!

See Also:
Constant Field Values

WOLF

public static final byte WOLF
DOCUMENT ME!

See Also:
Constant Field Values
Constructor Detail

WolfsheepGame

public WolfsheepGame()
initiates the game with the wolf being the first player


WolfsheepGame

public WolfsheepGame(byte firstPlayer)
can initiate the game with either the wolf or the sheeps as the first player;

See Also:
WOLF, SHEEP
Method Detail

listLegalMoves

protected GameMove[] listLegalMoves()
DOCUMENT ME!

Specified by:
listLegalMoves 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!

popMove

protected boolean popMove()
DOCUMENT ME!

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

nextPlayer

public int nextPlayer()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getWinner

public int[] getWinner()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getWolfPosition

public BoardPosition getWolfPosition()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getSheepPosition

public BoardPosition getSheepPosition(int index)
                               throws java.lang.ArrayIndexOutOfBoundsException
accepts index 0 - 3

Parameters:
index - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ArrayIndexOutOfBoundsException - 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!

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)