|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.AbstractGame
com.antelmann.game.wolfsheep.WolfsheepGame
public class WolfsheepGame
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.
BoardPosition,
Serialized Form| Field Summary | |
|---|---|
static byte |
SHEEP
|
static byte |
WOLF
|
| 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 | |
|---|---|
Object |
clone()
Any inheriting class with non-primitive members must override this clone() method to provide a full deep copy of the object, which is essential for spawnChild() to work correctly. |
boolean |
equals(Object obj)
|
BoardPosition |
getSheepPosition(int index)
accepts index 0 - 3 |
int[] |
getWinner()
getWinner() returns an array of all winning game roles - as there could be more than one winner. |
BoardPosition |
getWolfPosition()
|
protected GameMove[] |
listLegalMoves()
listLegalMoves() returns the legal moves for this game. |
int |
nextPlayer()
nextPlayer() returns the integer representing the game role of the next player. |
protected boolean |
popMove()
popMove undoes the last move by altering the game board to the stage before the last move happened. |
protected boolean |
pushMove(GameMove move)
pushMove takes a GameMove and alters the game according to to the move. |
String |
toString()
overridden to provide useful information about the game |
| Methods inherited from class com.antelmann.game.AbstractGame |
|---|
addObserver, clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getObservers, getRedoList, getResult, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, removeObserver, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final byte SHEEP
public static final byte WOLF
| Constructor Detail |
|---|
public WolfsheepGame()
public WolfsheepGame(byte firstPlayer)
WOLF,
SHEEP| Method Detail |
|---|
protected GameMove[] listLegalMoves()
AbstractGame
listLegalMoves in class AbstractGameprotected boolean pushMove(GameMove move)
AbstractGame
pushMove in class AbstractGameprotected boolean popMove()
AbstractGame
popMove in class AbstractGamepublic int nextPlayer()
GamePlay
public int[] getWinner()
GamePlay
public BoardPosition getWolfPosition()
public BoardPosition getSheepPosition(int index)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionpublic boolean equals(Object obj)
equals in class Objectpublic String toString()
AbstractGame
toString in class AbstractGame
public Object clone()
throws CloneNotSupportedException
AbstractGamespawnChild() to work correctly. Ay overriding
of this method should still begin with a call to
super.clone(), though.
Also, note that this clone() method does not clone the
embedded GameMove objects, i.e. those are expected not to change
(except for their heuristics, which shouldn't affect game
functionality) - or the subclass will have to take care of this.
clone in interface GamePlayclone in class AbstractGameCloneNotSupportedExceptionAbstractGame.spawnChild(GameMove)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||