org.jscience.computing.game
Class GameBoardMove

java.lang.Object
  extended by org.jscience.computing.game.GameBoardMove
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, GameMove

public class GameBoardMove
extends java.lang.Object
implements GameMove, java.lang.Cloneable

A specialized GameMove class suitable for board games to implement moves of pieces from and to positions on a board.

See Also:
Serialized Form

Field Summary
protected  java.lang.Object moveOption
          DOCUMENT ME!
protected  int playerRole
          DOCUMENT ME!
protected  GameBoardPosition positionFrom
          DOCUMENT ME!
protected  GameBoardPosition positionTo
          DOCUMENT ME!
 
Constructor Summary
GameBoardMove(int playerRole, GameBoardPosition position)
          Creates a new GameBoardMove object.
GameBoardMove(int playerRole, GameBoardPosition oldPosition, GameBoardPosition newPosition)
          Creates a new GameBoardMove object.
GameBoardMove(int playerRole, GameBoardPosition oldPosition, GameBoardPosition newPosition, java.lang.Object option)
          Creates a new GameBoardMove object.
GameBoardMove(int playerRole, GameBoardPosition position, java.lang.Object option)
          Creates a new GameBoardMove object.
 
Method Summary
 java.lang.Object clone()
          Due to protected access of Object.clone() and the Object type of moveOption, this clone() function does not clone the moveOption, but only references the same object is referenced from the original GameMove.
 boolean equals(java.lang.Object obj)
          DOCUMENT ME!
 GameBoardPosition getNewPosition()
          DOCUMENT ME!
 GameBoardPosition getOldPosition()
          DOCUMENT ME!
 java.lang.Object getOption()
          DOCUMENT ME!
 int getPlayer()
          DOCUMENT ME!
 GameBoardPosition getPosition()
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moveOption

protected java.lang.Object moveOption
DOCUMENT ME!


playerRole

protected int playerRole
DOCUMENT ME!


positionTo

protected GameBoardPosition positionTo
DOCUMENT ME!


positionFrom

protected GameBoardPosition positionFrom
DOCUMENT ME!

Constructor Detail

GameBoardMove

public GameBoardMove(int playerRole,
                     GameBoardPosition position)
Creates a new GameBoardMove object.

Parameters:
playerRole - DOCUMENT ME!
position - DOCUMENT ME!

GameBoardMove

public GameBoardMove(int playerRole,
                     GameBoardPosition position,
                     java.lang.Object option)
Creates a new GameBoardMove object.

Parameters:
playerRole - DOCUMENT ME!
position - DOCUMENT ME!
option - DOCUMENT ME!

GameBoardMove

public GameBoardMove(int playerRole,
                     GameBoardPosition oldPosition,
                     GameBoardPosition newPosition)
Creates a new GameBoardMove object.

Parameters:
playerRole - DOCUMENT ME!
oldPosition - DOCUMENT ME!
newPosition - DOCUMENT ME!

GameBoardMove

public GameBoardMove(int playerRole,
                     GameBoardPosition oldPosition,
                     GameBoardPosition newPosition,
                     java.lang.Object option)
Creates a new GameBoardMove object.

Parameters:
playerRole - DOCUMENT ME!
oldPosition - DOCUMENT ME!
newPosition - DOCUMENT ME!
option - DOCUMENT ME!
Method Detail

getPlayer

public int getPlayer()
DOCUMENT ME!

Specified by:
getPlayer in interface GameMove
Returns:
DOCUMENT ME!
See Also:
GamePlay.numberOfPlayers()

getOption

public java.lang.Object getOption()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getPosition

public GameBoardPosition getPosition()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getNewPosition

public GameBoardPosition getNewPosition()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getOldPosition

public GameBoardPosition getOldPosition()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

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

Overrides:
toString 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!

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Due to protected access of Object.clone() and the Object type of moveOption, this clone() function does not clone the moveOption, but only references the same object is referenced from the original GameMove. Thus, one should be aware that GameMove.clone() only does a shallow copy! The embedded GameBoardPositions are only shallow-copied because they cannot be changed after instanciation, i.e. it should not harm things; if derived classes are used, though, that may chance of course. Note: as a resolution, an overwriting clone() function that knows the type of the moveOption could cast the Object type of the moveOption to something where the clone() function of that object is accessible for a deep copy; this overwriting method could also take care of cloning the GameBoardPositions if needed (in case subclasses are used there, too).

Overrides:
clone in class java.lang.Object
Returns:
DOCUMENT ME!
Throws:
java.lang.CloneNotSupportedException - DOCUMENT ME!