org.moyoman.comm.client
Class PlayerManager

java.lang.Object
  |
  +--org.moyoman.comm.client.PlayerManager
Direct Known Subclasses:
PrerecordedPlayerManager

public class PlayerManager
extends Object

This class manages the play of a single game of Go


Field Summary
private  Player blackPlayer
          The player playing black.
private  CommandExecutor ce
           
private  boolean continueFlag
          If singleStepFlag is true, then play pauses until this variable is set to true.
private  boolean singleStepFlag
          If true, then play pauses after each move.
private  Color toMove
          The color of the player to move next.
private  Player whitePlayer
          The player playing white.
 
Constructor Summary
PlayerManager(Player black, Player white)
          Create the PlayerManager object.
PlayerManager(Player black, Player white, GameRecord gr)
          Create a PlayerManager object to continue play for the specified game.
 
Method Summary
private  boolean blackMove()
          Get a move from the black player, and send it to the white player.
 Player getBlackPlayer()
           
 GameRecord getGameRecord()
          Get the game record for this game.
 MoyomanPlayer[] getMoyomanPlayers()
          Return an array of MoyomanPlayer objects.
 MoveDescriptor getSuggestedMove()
           
 Player getWhitePlayer()
           
private  Color initializeBoard(GameRecord gr)
          Initialize the board for the two players.
 boolean isSingleStep()
          Determine whether the single step flag is set.
private  void pause()
          Pause the game until receiving a signal to continue.
 void play()
          Play a game of Go, using the two Player objects.
protected  Color playPrerecordedMoves(GameRecord gr, boolean blackFlag, boolean whiteFlag)
          Play out a game record of prerecorded moves.
 void setSingleStepFlag(boolean flag)
          Set the single step flag.
 void singleStep()
          Cause one more move to be made.
 boolean takeBackMove()
          Return to an earlier state in the game.
private  boolean whiteMove()
          Get a move from the white player, and send it to the black player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blackPlayer

private Player blackPlayer
The player playing black.


whitePlayer

private Player whitePlayer
The player playing white.


toMove

private Color toMove
The color of the player to move next.


singleStepFlag

private boolean singleStepFlag
If true, then play pauses after each move.


continueFlag

private boolean continueFlag
If singleStepFlag is true, then play pauses until this variable is set to true.


ce

private CommandExecutor ce
Constructor Detail

PlayerManager

public PlayerManager(Player black,
                     Player white)
              throws InternalErrorException
Create the PlayerManager object.

Parameters:
black - The Player which is playing black.
white - The Player which is playing white.

PlayerManager

public PlayerManager(Player black,
                     Player white,
                     GameRecord gr)
              throws InternalErrorException
Create a PlayerManager object to continue play for the specified game.

Parameters:
black - - The black player
white - - The white player
gr - - The game record of the position to resume from.
Throws:
InternalErrorException - - Thrown if an error occurs in starting the game from the position in the game record.
Method Detail

getBlackPlayer

public Player getBlackPlayer()

getWhitePlayer

public Player getWhitePlayer()

singleStep

public void singleStep()
Cause one more move to be made. This method only needs to be called when the single step flag has been set. Each time it is called, the player whose turn it is is allowed to make his move. The purpose of the single step mode is to allow the user to examine the debug output for each move.


setSingleStepFlag

public void setSingleStepFlag(boolean flag)
Set the single step flag. If true, then the singleStep method needs to be called before another move can be made. If false, then play proceeds at the pace of the two players.

Parameters:
flag - If true, then single step through the game.

isSingleStep

public boolean isSingleStep()
Determine whether the single step flag is set.

Returns:
true if the single step flag is set, or false.

play

public void play()
          throws InternalErrorException
Play a game of Go, using the two Player objects.

Throws:
InternalErrorException - Thrown if the game cannot be played for any reason, such as differing initial board for the two players.

takeBackMove

public boolean takeBackMove()
                     throws InconsistentStateException,
                            InternalErrorException
Return to an earlier state in the game. The method name is a slight misnomer, since the last two moves are taken back.

Returns:
true if the game is reverted to the earlier state, or false.
Throws:
InconsistentStateException - - Thrown if the moves are taken back for one player but not the other. There should be rollback functionality to take care of this case.
InternalErrorException - - Thrown if an error occurs for any reason.

blackMove

private boolean blackMove()
                   throws InternalErrorException
Get a move from the black player, and send it to the white player. The method will pause before getting the move from black if the single step flag is set.

Returns:
true if the game is now over, or false.
Throws:
InternalErrorException - - Thrown is an error occurs for any reason.

whiteMove

private boolean whiteMove()
                   throws InternalErrorException
Get a move from the white player, and send it to the black player. The method will pause before getting the move from white if the single step flag is set.

Returns:
true if the game is now over, or false.
Throws:
InternalErrorException - - Thrown is an error occurs for any reason.

pause

private void pause()
Pause the game until receiving a signal to continue. The game is paused if the single step flag is set until the continue flag is set. The continue flag is then set to false, and the method returns.


initializeBoard

private Color initializeBoard(GameRecord gr)
                       throws InternalErrorException
Initialize the board for the two players. The players are responsible for adding any handicap stones. For the case where a game is being resumed, players that are not self initializing have all of the moves of the game added to them one move at a time.

Returns:
The color of the player to play next.
Throws:
InternalErrorException - Thrown if the game cannot be played for any reason, such as differing initial boards for the two players.

playPrerecordedMoves

protected Color playPrerecordedMoves(GameRecord gr,
                                     boolean blackFlag,
                                     boolean whiteFlag)
                              throws InternalErrorException
Play out a game record of prerecorded moves.

Parameters:
gr - The game record of the moves to be played out.
blackFlag - Only make calls on black player if this is false.
whiteFlag - Only make calls on white player if this is false.
Returns:
A Color object which is the color of the next player to play.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getMoyomanPlayers

public MoyomanPlayer[] getMoyomanPlayers()
Return an array of MoyomanPlayer objects. The client will need to distinguish between MoyomanPlayer players and other types of players because of functionality such as the debug window.

Returns:
An array of MoyomanPlayer objects.

getGameRecord

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

Returns:
A GameRecord object which is the record of this game so far.
Throws:
InternalErrorException - Thrown if the game record cannot be retrieved for any reason.

getSuggestedMove

public MoveDescriptor getSuggestedMove()
                                throws RuntimeException
RuntimeException