Holger's
Java API

com.antelmann.game.awari
Class AwariGame

java.lang.Object
  extended by com.antelmann.game.AbstractGame
      extended by com.antelmann.game.awari.AwariGame
All Implemented Interfaces:
GamePlay, Serializable, Cloneable

public class AwariGame
extends AbstractGame

AwariGame implements an ancient African game (for all I know). The board positions are configured as follows:

    13 12 11 10  9  8
  0                    7
     1  2  3  4  5  6
 

Author:
Holger Antelmann
See Also:
Serialized Form

Constructor Summary
AwariGame()
           
 
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.
 int getBaseCount(int player)
           
 double getLead(int playerRole)
          returns the lead as in difference in number of pegs during the game
 double getResult(int playerRole)
          returns the difference in number of pegs once the game is over
 int[] getWinner()
          if the game is even, all players win
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, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, removeObserver, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AwariGame

public AwariGame()
Method Detail

listLegalMoves

protected GameMove[] listLegalMoves()
Description copied from class: AbstractGame
listLegalMoves() returns the legal moves for this game. This function is used by the final method getLegalMoves(), which is a wrapper around this method to avoid the overhead of generating the legal moves over and over again when called multiple times (as calculating legal moves is commonly expensive). Note that implementations of listLegalMoves() must not check for gameOver(), unless gameOver() is overridden not to check for listLegalMoves(). The same applies to isLegalMove().

Specified by:
listLegalMoves in class AbstractGame

pushMove

protected boolean pushMove(GameMove move)
Description copied from class: AbstractGame
pushMove takes a GameMove and alters the game according to to the move.

Specified by:
pushMove in class AbstractGame
Returns:
true only if the move was put on the board successfully.

popMove

protected boolean popMove()
Description copied from class: AbstractGame
popMove undoes the last move by altering the game board to the stage before the last move happened.

Specified by:
popMove in class AbstractGame
Returns:
true only if the move was taken back successfully.

nextPlayer

public int nextPlayer()
Description copied from interface: GamePlay
nextPlayer() returns the integer representing the game role of the next player. If there is no next player, it is assumed that there are no more legal moves left in the game, in which case the value of nextPlayer() should be irrelevant.


getWinner

public int[] getWinner()
if the game is even, all players win


getResult

public double getResult(int playerRole)
                 throws GameRuntimeException
returns the difference in number of pegs once the game is over

Specified by:
getResult in interface GamePlay
Overrides:
getResult in class AbstractGame
Returns:
1 if game is won, -1 if game is lost and 0 if no winners are present
Throws:
GameRuntimeException - if the game is still in progress

getLead

public double getLead(int playerRole)
returns the lead as in difference in number of pegs during the game


getBaseCount

public int getBaseCount(int player)

toString

public String toString()
Description copied from class: AbstractGame
overridden to provide useful information about the game

Overrides:
toString in class AbstractGame

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from class: AbstractGame
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. 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.

Specified by:
clone in interface GamePlay
Overrides:
clone in class AbstractGame
Throws:
CloneNotSupportedException
See Also:
AbstractGame.spawnChild(GameMove)


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads