org.moyoman.comm.client
Class Player

java.lang.Object
  |
  +--org.moyoman.comm.client.Player
Direct Known Subclasses:
NonvalidatedPlayer, ValidatedPlayer

public abstract class Player
extends Object

Any class which extends this class can be used by the PlayerManager class as one of the players in a game of Go. Some examples of these classes are a human user at the keyboard, the Moyoman back-end sever, and a player communicating through a socket using the GTP protocol.


Field Summary
protected  Color color
          The color of this player.
private  ArrayList endOfGameAl
          Each object an ArrayList containing EndOfGameListener objects.
protected  Handicap handicap
          The handicap for this game.
private  ArrayList makeMoveAl
          Each object is an ArrayList containing MakeMoveListener objects.
private  ArrayList requestMoveAl
          Each object is an ArrayList containing RequestMoveListener objects.
 
Constructor Summary
Player(Color c, Handicap h)
          Create the Player object.
 
Method Summary
abstract  void derivedMakeMove(MoveDescriptor md)
          Make a move.
abstract  MoveDescriptor derivedRequestMove()
          Get a move from the player.
private  void endOfGameEventOccurred()
          Send all EndOfGameListeners which are registered an EndOfGameEvent.
 Color getColor()
          Get the color of the player.
abstract  GameRecord getGameRecord()
          Get the game record for this player.
 Handicap getHandicap()
          Get the handicap of the game.
abstract  String getId()
          Return a String which is the game id.
abstract  String getIdentifyingInfo()
          Return a String which identifies the player.
abstract  short getMoveNumber()
          Get the move number.
abstract  boolean isSelfInitializingUser()
          Return whether the player initializes itself on startup.
abstract  boolean isValidatedUser()
          Return whether the player validates the legality of its moves.
 void makeMove(MoveDescriptor md)
          Make a move.
private  void makeMoveEventOccurred(MoveDescriptor md)
          Send all MakeMoveListeners which are registered a MakeMoveEvent.
protected  void makeMoveNoEvents(MoveDescriptor md)
          Make a move without throwing any make move events.
 void registerEndOfGameMoveListener(EndOfGameListener eogl)
          Add a EndOfGameMoveListener for end of game events on this Player.
 void registerMakeMoveListener(MakeMoveListener mml)
          Add a MakeMoveListener for makeMove() calls on this Player.
 void registerRequestMoveListener(RequestMoveListener rml)
          Add a RequestMoveListener for requestMove() calls on this Player.
 MoveDescriptor requestMove()
          Get a move from the player.
private  void requestMoveEventOccurred(MoveDescriptor md)
          Send all RequestMoveListeners which are registered a RequestMoveEvent.
 void unregisterEndOfGameListeners()
          Remove all EndOfGameListeners for this player.
 void unregisterMakeMoveListeners()
          Remove all MakeMoveListeners for this player.
 void unregisterRequestMoveListeners()
          Remove all RequestMoveListeners for this player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

color

protected Color color
The color of this player.


handicap

protected Handicap handicap
The handicap for this game.


makeMoveAl

private ArrayList makeMoveAl
Each object is an ArrayList containing MakeMoveListener objects.


requestMoveAl

private ArrayList requestMoveAl
Each object is an ArrayList containing RequestMoveListener objects.


endOfGameAl

private ArrayList endOfGameAl
Each object an ArrayList containing EndOfGameListener objects.

Constructor Detail

Player

public Player(Color c,
              Handicap h)
       throws InternalErrorException
Create the Player object.

Parameters:
c - The color of the player.
h - The handicap for the game.
Throws:
InternalErrorException - - Thrown if an error occurs while creating the player.
Method Detail

makeMove

public final void makeMove(MoveDescriptor md)
                    throws IllegalMoveException,
                           InternalErrorException
Make a move. Derived classes override the derivedMakeMove() method. This method, which cannot be overriden, makes sure that the appropriate make move and end of game events occur.

Parameters:
md - The MoveDescriptor which describes the move to make.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

makeMoveNoEvents

protected final void makeMoveNoEvents(MoveDescriptor md)
                               throws IllegalMoveException,
                                      InternalErrorException
Make a move without throwing any make move events. This is used for loading games and restoring non self initializing players.

Parameters:
md - The MoveDescriptor which describes the move to make.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

requestMove

public final MoveDescriptor requestMove()
                                 throws IllegalMoveException,
                                        InternalErrorException
Get a move from the player. Derived classes override the derivedRequestMove() method. This method, which cannot be overriden, make sure that the appropriate request move and end of game events occur.

Returns:
A MoveDescriptor object which describes the move.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

derivedMakeMove

public abstract void derivedMakeMove(MoveDescriptor md)
                              throws IllegalMoveException,
                                     InternalErrorException
Make a move. The derived class must implement this method.

Parameters:
md - The MoveDescriptor which describes the move to make.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

derivedRequestMove

public abstract MoveDescriptor derivedRequestMove()
                                           throws IllegalMoveException,
                                                  InternalErrorException
Get a move from the player. The derived class must implement this method.

Returns:
A MoveDescriptor object which describes the move.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

getMoveNumber

public abstract short getMoveNumber()
                             throws InternalErrorException
Get the move number. The move number is the number of the next move to play, where the first non-handicap stone move is 1.

Returns:
The move number as a short.
InternalErrorException

getColor

public Color getColor()
Get the color of the player.

Returns:
The color of the player.

getHandicap

public Handicap getHandicap()
Get the handicap of the game.

Returns:
The handicap of the game.

isValidatedUser

public abstract boolean isValidatedUser()
Return whether the player validates the legality of its moves.

Returns:
true if the user validates its moves, or false.

isSelfInitializingUser

public abstract boolean isSelfInitializingUser()
Return whether the player initializes itself on startup. All players will set their own handicaps. If false, then when a saved game is reloaded, this player requires that the existing game be set explicitly, through multiple calls to makeMove().

Returns:
true if self initializing, or false.

getGameRecord

public abstract GameRecord getGameRecord()
                                  throws InternalErrorException
Get the game record for this player.

Returns:
A GameRecord object.
Throws:
InternalErrorException - Thrown if the game record cannot be retrieved for any reason.

getIdentifyingInfo

public abstract String getIdentifyingInfo()
Return a String which identifies the player.

Returns:
A String object such as "MoyomanPlayer".

getId

public abstract String getId()
                      throws NoSuchDataException
Return a String which is the game id.

Returns:
A String which is the game id.
Throws:
NoSuchDataException - - Thrown if the player does not have a game id.

registerMakeMoveListener

public void registerMakeMoveListener(MakeMoveListener mml)
Add a MakeMoveListener for makeMove() calls on this Player.

Parameters:
mml - - The MakeMoveListener to be added.

registerRequestMoveListener

public void registerRequestMoveListener(RequestMoveListener rml)
Add a RequestMoveListener for requestMove() calls on this Player.

Parameters:
rml - - The RequestMoveListener to be added.

registerEndOfGameMoveListener

public void registerEndOfGameMoveListener(EndOfGameListener eogl)
Add a EndOfGameMoveListener for end of game events on this Player. An end of game event can occur during a makeMove() or requestMove() call.

Parameters:
eogl - - The EndOfGameListener to be added.

unregisterMakeMoveListeners

public void unregisterMakeMoveListeners()
Remove all MakeMoveListeners for this player.


unregisterRequestMoveListeners

public void unregisterRequestMoveListeners()
Remove all RequestMoveListeners for this player.


unregisterEndOfGameListeners

public void unregisterEndOfGameListeners()
Remove all EndOfGameListeners for this player.


makeMoveEventOccurred

private void makeMoveEventOccurred(MoveDescriptor md)
Send all MakeMoveListeners which are registered a MakeMoveEvent.

Parameters:
md - The MoveDescriptor object.

requestMoveEventOccurred

private void requestMoveEventOccurred(MoveDescriptor md)
Send all RequestMoveListeners which are registered a RequestMoveEvent.

Parameters:
md - The MoveDescriptor object.

endOfGameEventOccurred

private void endOfGameEventOccurred()
Send all EndOfGameListeners which are registered an EndOfGameEvent.