org.moyoman.comm.client
Class NonvalidatedPlayer

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

public abstract class NonvalidatedPlayer
extends Player

Any class which extends this class can be used as one of the players in a game of Go. Players which derive from this class do not perform error checking on the moves which they make. This class handles that task so that the derived class does not have to. Some examples of these classes are a human user with the mouse and a player communicating through a socket using the GTP protocol.


Field Summary
private  Stone ko
          This is the move which would result in illegally retaking the ko, or null.
private  MoveValidator mv
          This object is used to validate the moves.
private  Stone[] suicide
          Any of the Stone objects in this array would be an illegal move because of suicide.
private  Stone[] superko
          Any of the Stone objects in this array would be an illegal move because of superko.
 
Fields inherited from class org.moyoman.comm.client.Player
color, handicap
 
Constructor Summary
  NonvalidatedPlayer(Color c, Handicap h)
          Create the NonvalidatedPlayer object.
protected NonvalidatedPlayer(Color c, Handicap h, String id)
           
 
Method Summary
 void derivedMakeMove(MoveDescriptor md)
          Make a move, and validate it.
 MoveDescriptor derivedRequestMove()
          Request a move, and validate it.
 GameRecord getGameRecord()
          Get the game record for this player.
 String getId()
          Return the id for the move validator.
 Stone getKo()
          Return the stone which would be an illegal retaking of the ko.
 short getMoveNumber()
          Get the move number.
protected abstract  Move getRequestedMove()
          The derived class must override this method to get a move from the player.
 boolean isSelfInitializingUser()
          Return whether the player initializes itself on startup.
 boolean isValidatedUser()
          Returns false, since all derived classes of this one do not validate their own moves.
protected abstract  void makeValidatedMove(MoveDescriptor md)
          The derived class must override this method to make a move.
private  void setKo(Stone ko)
          This method sets the move that is illegal because it immediately retakes the ko.
private  void setSuicideMoves(Stone[] moves)
          This method sets the moves that are illegal because of suicide.
private  void setSuperKoMoves(Stone[] moves)
          This method sets the moves that are illegal because of superko.
 void validateMove(Stone move)
          This method exits normally if the move is legal, or throws an exception otherwise.
 
Methods inherited from class org.moyoman.comm.client.Player
getColor, getHandicap, getIdentifyingInfo, makeMove, makeMoveNoEvents, registerEndOfGameMoveListener, registerMakeMoveListener, registerRequestMoveListener, requestMove, unregisterEndOfGameListeners, unregisterMakeMoveListeners, unregisterRequestMoveListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mv

private MoveValidator mv
This object is used to validate the moves.


ko

private Stone ko
This is the move which would result in illegally retaking the ko, or null.


suicide

private Stone[] suicide
Any of the Stone objects in this array would be an illegal move because of suicide.


superko

private Stone[] superko
Any of the Stone objects in this array would be an illegal move because of superko.

Constructor Detail

NonvalidatedPlayer

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

Parameters:
c - The color of the player.
h - The handicap of the game.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

NonvalidatedPlayer

protected NonvalidatedPlayer(Color c,
                             Handicap h,
                             String id)
                      throws InternalErrorException
Method Detail

derivedMakeMove

public final void derivedMakeMove(MoveDescriptor md)
                           throws IllegalMoveException,
                                  InternalErrorException
Make a move, and validate it.

Specified by:
derivedMakeMove in class Player
Parameters:
md - The MoveDescriptor which describes the move to make.
Throws:
IllegalMoveException - - Thrown if the move to be made is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

makeValidatedMove

protected abstract void makeValidatedMove(MoveDescriptor md)
                                   throws IllegalMoveException,
                                          InternalErrorException
The derived class must override this method to make a move. The move has already been validated before this method is called.

Parameters:
md - The move to be made.
Throws:
IllegalMoveException - - Thrown if the move to be made is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

derivedRequestMove

public final MoveDescriptor derivedRequestMove()
                                        throws IllegalMoveException,
                                               InternalErrorException
Request a move, and validate it.

Specified by:
derivedRequestMove in class Player
Returns:
A MoveDescriptor object which describes the move.
Throws:
IllegalMoveException - - Thrown if the move to be made is illegal.
InternalErrorException - Thrown if the operation fails for any reason.

getMoveNumber

public short getMoveNumber()
                    throws InternalErrorException
Get the move number.

Specified by:
getMoveNumber in class Player
Returns:
A short which is the next move to play.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getGameRecord

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

Specified by:
getGameRecord in class Player
Returns:
A GameRecord object.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getRequestedMove

protected abstract Move getRequestedMove()
The derived class must override this method to get a move from the player. The move returned by this method will be validated by derivedRequestMove().

Returns:
The move to be made.

isValidatedUser

public boolean isValidatedUser()
Returns false, since all derived classes of this one do not validate their own moves.

Specified by:
isValidatedUser in class Player
Returns:
false.

setKo

private void setKo(Stone ko)
This method sets the move that is illegal because it immediately retakes the ko.

Parameters:
ko - The stone which is an illegal move without making a ko threat. This parameter may be null if there is no ko.

setSuicideMoves

private void setSuicideMoves(Stone[] moves)
This method sets the moves that are illegal because of suicide.

Parameters:
moves - An array of Stone objects.

setSuperKoMoves

private void setSuperKoMoves(Stone[] moves)
This method sets the moves that are illegal because of superko.

Parameters:
moves - An array of Stone objects.

getKo

public Stone getKo()
Return the stone which would be an illegal retaking of the ko.

Returns:
A Stone object representing the illegal taking of the ko, or null.

validateMove

public void validateMove(Stone move)
                  throws IllegalMoveException
This method exits normally if the move is legal, or throws an exception otherwise.

Parameters:
move - The move in question.
Throws:
A - derived class of IllegalMoveException corresponding to the reason why the move is illegal.
IllegalMoveException

isSelfInitializingUser

public boolean isSelfInitializingUser()
Description copied from class: Player
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().

Specified by:
isSelfInitializingUser in class Player
Returns:
true if self initializing, or false.

getId

public String getId()
Return the id for the move validator.

Specified by:
getId in class Player
Returns:
The game id.