org.moyoman.module.board.boardimpl
Class BoardImpl

java.lang.Object
  |
  +--org.moyoman.module.Module
        |
        +--org.moyoman.module.board.boardimpl.BoardImpl
All Implemented Interfaces:
Board, Cloneable, Component, ModuleInterface, Serializable

public class BoardImpl
extends Module
implements Board

This module implements the Board interface. It is responsible for maintaining information about the state of the board, and things such as legal moves, prisoners, etc.

See Also:
Serialized Form

Field Summary
private  ArrayList allPrisoners
          Store information about all prisoners during the game.
private  boolean isGenerated
          This indicates if makeMove() was called immediately after generateMove().
private  ArrayList kos
          Store information about all kos during the game.
private  Color moveColor
          The color to move next.
private  short moveNumber
          The move number for the next turn.
private  ArrayList moves
          Store all of the moves for the game, including handicap stones.
private static ModuleType[] mt
          The modules that this module is dependent on.
private  ArrayList prisoners
          Store information about prisoners on the last move.
private  ArrayList ratedMoves
          Give the illegal moves a large negative rating.
private  RulesHelper rhelper
          The RulesHelper object that determines the legality of moves.
private  Color[][] stones
          Each element of the array represents the color of that point on the board.
 
Fields inherited from class org.moyoman.module.Module
 
Fields inherited from interface org.moyoman.module.board.Board
ALLOWED, DRAW, FILLED, FORBIDDEN, KO, LEGAL, SUICIDE, SUPERKO, WRONG_COLOR
 
Constructor Summary
BoardImpl(GameId id, ModuleName name)
          Create a new BoardImpl object.
 
Method Summary
 Object clone()
          Override the Object.clone() method.
 boolean didSuicideOccur()
          Return true if the last move was a suicide, or false.
 boolean doCountPointsInSeki()
          Determine if the territory in a seki is counted.
 boolean freePlacementOfHandicapStones()
          Determine if handicap stones must be placed in arbitrary positions.
 void generateMove(Module[] modules)
          Rate different moves that could be made by the current player.
 NumberedStone[] getAllBlackPrisoners()
          Return all of the black prisoners which have occurred during the game.
 NumberedStone[] getAllKos()
          Return all of the kos which have occurred during the game.
 Move[] getAllMoves()
          Get all moves which have been made in this game.
 NumberedStone[] getAllPrisoners()
          Return all of the prisoners which have occurred during the game.
 NumberedStone[] getAllWhitePrisoners()
          Return all of the white prisoners which have occurred during the game.
 Stone[] getBlackStones()
          Get all of the black stones on the board.
 Color[][] getBoardArray()
          Get a two dimensional array of Color objects representing the current board position.
 Color getColor(Point pt)
          Get the color for a given point on the board.
 Color getColorToMove()
          Get the color of the player to move next.
 Debug[] getDebugInformation(DebugType[] types)
          Get the debug information for this module.
 DebugType[] getDebugTypes()
          Get the debug types which this module supports.
 Stone[] getIllegalMoves()
          Return all moves which would be illegal for whatever reason.
 float getKomi()
          Return the komi for this game.
 Move getLastMove()
          Get the last move.
 MoveDescriptor getLastMoveDescriptor()
          Get a MoveDescriptor describing the last move.
 Stone getLastMoveKo()
          Return the move which would illegaly retake the ko.
 short getLastMovePrisonerCount()
          Return the number of prisoners captured on the last move.
 Stone[] getLastMovePrisoners()
          Return the prisoners which were captured on the last move.
 short getLegalityStatus(Stone st)
          Determine the legality of the given move.
 Stone[] getLegalMoves()
          Get all of the legal moves.
 short getMoveNumber()
          Get the move number.
 RatedMove[] getMoves()
          Get the moves rated by this module.
 ModuleType[] getRequiredModuleList()
          Get the modules that this module uses.
 short getStoneCount()
          Get the total number of stones on the board.
 Stone[] getStones()
          Get all of the stones on the board.
 Stone[] getSuicideMoves()
          Return all moves which are illegal because of suicide.
 Stone[] getSuperKoMoves()
          Return all moves which are illegal because they recreate a previous board position.
 short getTotalBlackPrisonerCount()
          Return the total number of black prisoners captured.
 short getTotalWhitePrisonerCount()
          Return the total number of white prisoners captured.
 Stone[] getWhiteStones()
          Get all of the white stones on the board.
 boolean isBentFourDeadByRule()
          Determine if a bent four in the corner is automatically dead.
 boolean isEndOfGame()
          Determine if the last move ended the game.
 boolean isLegal(Stone st)
          Determine if the given move is legal.
 boolean isSuicideAllowed()
          Determine if suicide is legal.
 boolean isTerritoryScoring()
          Determine if the scoring method is by territory.
 void makeMove(Move move)
          Update this module with the move which has been made.
 void makeMove(Move move, Module[] modules)
          Update this module with the move which has been made.
 boolean mustWhiteMoveLast()
          Determine if white must move last.
 short numberOfPassesToEndGame()
          Determine the number of consecutive passes to end the game.
 short superKoRule()
          Determine the legality of a super ko.
 String toString()
          Return a String representation of the board.
private  void updateState(Move move)
          Update the state variables as a result of the move.
 
Methods inherited from class org.moyoman.module.Module
checkTime, create, createHelper, debug, error, error, fatal, fatal, getAllHelpers, getHelper, getId, getModule, getModuleName, getScheduler, information, setTime, warning, warning
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.moyoman.module.ModuleInterface
getScheduler
 

Field Detail

mt

private static ModuleType[] mt
The modules that this module is dependent on.


kos

private ArrayList kos
Store information about all kos during the game.


allPrisoners

private ArrayList allPrisoners
Store information about all prisoners during the game.


prisoners

private ArrayList prisoners
Store information about prisoners on the last move.


ratedMoves

private ArrayList ratedMoves
Give the illegal moves a large negative rating.


moves

private ArrayList moves
Store all of the moves for the game, including handicap stones.


rhelper

private RulesHelper rhelper
The RulesHelper object that determines the legality of moves.


stones

private Color[][] stones
Each element of the array represents the color of that point on the board.


moveNumber

private short moveNumber
The move number for the next turn.


moveColor

private Color moveColor
The color to move next.


isGenerated

private boolean isGenerated
This indicates if makeMove() was called immediately after generateMove().

Constructor Detail

BoardImpl

public BoardImpl(GameId id,
                 ModuleName name)
          throws InternalErrorException
Create a new BoardImpl object.

Parameters:
id - The id of the game.
name - The ModuleName object corresponding to this module.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Method Detail

getColorToMove

public Color getColorToMove()
Get the color of the player to move next.

Specified by:
getColorToMove in interface Board
Returns:
A Color object, which is the side to move.

isTerritoryScoring

public boolean isTerritoryScoring()
Determine if the scoring method is by territory.

Specified by:
isTerritoryScoring in interface Board
Returns:
true if scoring is by territory, or false if by stones and area.

doCountPointsInSeki

public boolean doCountPointsInSeki()
Determine if the territory in a seki is counted.

Specified by:
doCountPointsInSeki in interface Board
Returns:
true if the points count, or false.

isSuicideAllowed

public boolean isSuicideAllowed()
Determine if suicide is legal.

Specified by:
isSuicideAllowed in interface Board
Returns:
true if suicide is allowed, or false.

superKoRule

public short superKoRule()
Determine the legality of a super ko.

Specified by:
superKoRule in interface Board
Returns:
A short which is either DRAW, FORBIDDEN, or ALLOWED.

isBentFourDeadByRule

public boolean isBentFourDeadByRule()
Determine if a bent four in the corner is automatically dead. Under some rule sets, a bent four in the corner is not treated as a special event. Under others, the surrounding group is automatically dead.

Specified by:
isBentFourDeadByRule in interface Board
Returns:
true if bent four in the corner is dead by rule, or false.

mustWhiteMoveLast

public boolean mustWhiteMoveLast()
Determine if white must move last. When a player passes, he gives up one prisoner. If this method returns true, then if black makes the last move, white must give up an additonal prisoner.

Specified by:
mustWhiteMoveLast in interface Board
Returns:
true if white must move last, or false.

freePlacementOfHandicapStones

public boolean freePlacementOfHandicapStones()
Determine if handicap stones must be placed in arbitrary positions. Under some rule sets, the handicap stones may be placed anywhere.

Specified by:
freePlacementOfHandicapStones in interface Board
Returns:
true if the handicap stones may be place anywhere, or false if they must be placed in a fixed pattern.

numberOfPassesToEndGame

public short numberOfPassesToEndGame()
Determine the number of consecutive passes to end the game.

Specified by:
numberOfPassesToEndGame in interface Board
Returns:
A short which is the number of passes which ends the game.

getKomi

public float getKomi()
Return the komi for this game.

Specified by:
getKomi in interface Board
Overrides:
getKomi in class Module
Returns:
A float which is the komi.

getLastMoveKo

public Stone getLastMoveKo()
Return the move which would illegaly retake the ko.

Specified by:
getLastMoveKo in interface Board
Returns:
A Stone object, or null if there is no ko.

getSuicideMoves

public Stone[] getSuicideMoves()
Return all moves which are illegal because of suicide.

Specified by:
getSuicideMoves in interface Board
Returns:
An array of Stone objects.

getSuperKoMoves

public Stone[] getSuperKoMoves()
Return all moves which are illegal because they recreate a previous board position. This does not include moves which illegally retake a simple ko.

Specified by:
getSuperKoMoves in interface Board
Returns:
An array of Stone objects.

getIllegalMoves

public Stone[] getIllegalMoves()
Return all moves which would be illegal for whatever reason. This is the union of getLastMoveKo(), getSuicideMoves(), and getSuperKoMoves(), as well as points which are not empty.

Specified by:
getIllegalMoves in interface Board
Returns:
An array of Stone objects.

getAllKos

public NumberedStone[] getAllKos()
Return all of the kos which have occurred during the game.

Specified by:
getAllKos in interface Board
Returns:
An array of NumberedStone objects.

getAllPrisoners

public NumberedStone[] getAllPrisoners()
Return all of the prisoners which have occurred during the game.

Specified by:
getAllPrisoners in interface Board
Returns:
An array of NumberedStone objects.

getAllBlackPrisoners

public NumberedStone[] getAllBlackPrisoners()
Return all of the black prisoners which have occurred during the game.

Specified by:
getAllBlackPrisoners in interface Board
Returns:
An array of NumberedStone objects.

getAllWhitePrisoners

public NumberedStone[] getAllWhitePrisoners()
Return all of the white prisoners which have occurred during the game.

Specified by:
getAllWhitePrisoners in interface Board
Returns:
An array of NumberedStone objects.

getLastMovePrisoners

public Stone[] getLastMovePrisoners()
Return the prisoners which were captured on the last move.

Specified by:
getLastMovePrisoners in interface Board
Returns:
An array of Stone objects.

isLegal

public boolean isLegal(Stone st)
Determine if the given move is legal.

Specified by:
isLegal in interface Board
Parameters:
st - The stone object.
Returns:
true if the stone is a legal move, or false.

getLegalityStatus

public short getLegalityStatus(Stone st)
Determine the legality of the given move.

Specified by:
getLegalityStatus in interface Board
Parameters:
st - The move being tested.
Returns:
A short which is one of the following Board constants:
  1. LEGAL
  2. FILLED
  3. SUICIDE
  4. KO
  5. SUPERKO
  6. WRONG_COLOR

getLegalMoves

public Stone[] getLegalMoves()
Get all of the legal moves.

Specified by:
getLegalMoves in interface Board
Returns:
An array of Stone objects.

getTotalBlackPrisonerCount

public short getTotalBlackPrisonerCount()
Return the total number of black prisoners captured.

Specified by:
getTotalBlackPrisonerCount in interface Board
Returns:
A short which is the total black prisoner count.

getTotalWhitePrisonerCount

public short getTotalWhitePrisonerCount()
Return the total number of white prisoners captured.

Specified by:
getTotalWhitePrisonerCount in interface Board
Returns:
A short which is the total white prisoner count.

getLastMovePrisonerCount

public short getLastMovePrisonerCount()
Return the number of prisoners captured on the last move.

Specified by:
getLastMovePrisonerCount in interface Board
Returns:
A short which is the number of prisoners captured on the last move.

getLastMove

public Move getLastMove()
                 throws NoSuchDataException
Get the last move.

Specified by:
getLastMove in interface Board
Returns:
A Move object.
Throws:
NoSuchDataException - Thrown if the board is empty or only contains handicap stones.

getLastMoveDescriptor

public MoveDescriptor getLastMoveDescriptor()
                                     throws NoSuchDataException
Get a MoveDescriptor describing the last move.

Specified by:
getLastMoveDescriptor in interface Board
Returns:
A MoveDescriptor object.
Throws:
NoSuchDataException - Thrown if the board is empty or only contains handicap stones.

getColor

public Color getColor(Point pt)
Get the color for a given point on the board.

Specified by:
getColor in interface Board
Parameters:
pt - The point in question.
Returns:
A Color object which is either Color.BLACK, Color.WHITE, or Color.EMPTY.

getBlackStones

public Stone[] getBlackStones()
Get all of the black stones on the board.

Specified by:
getBlackStones in interface Board
Returns:
An array of Stone objects.

getWhiteStones

public Stone[] getWhiteStones()
Get all of the white stones on the board.

Specified by:
getWhiteStones in interface Board
Returns:
An array of Stone objects.

getStones

public Stone[] getStones()
Get all of the stones on the board.

Specified by:
getStones in interface Board
Returns:
An array of Stone objects.

getStoneCount

public short getStoneCount()
Get the total number of stones on the board.

Specified by:
getStoneCount in interface Board
Returns:
A short which is the total number of stones on the board.

generateMove

public void generateMove(Module[] modules)
Rate different moves that could be made by the current player. The algorithm is very simple; just rate the illegal moves with a low score with high confidence.

Specified by:
generateMove in class Module
Parameters:
modules - The modules upon which this module is dependent.

getBoardArray

public Color[][] getBoardArray()
Get a two dimensional array of Color objects representing the current board position. For a given stone, it is represented in this array at position st.getX(), st.getY().

Specified by:
getBoardArray in interface Board
Returns:
A two dimensional array of Color objects.

getDebugInformation

public Debug[] getDebugInformation(DebugType[] types)
Get the debug information for this module.

Specified by:
getDebugInformation in class Module
Parameters:
types - The debug types which are requested.
Returns:
An array of Debug objects.

getDebugTypes

public DebugType[] getDebugTypes()
Get the debug types which this module supports.

Specified by:
getDebugTypes in class Module
Returns:
An array of DebugType objects.

getAllMoves

public Move[] getAllMoves()
Get all moves which have been made in this game.

Specified by:
getAllMoves in interface Board
Returns:
An array of Move objects.

getMoves

public RatedMove[] getMoves()
Get the moves rated by this module.

Specified by:
getMoves in interface ModuleInterface
Specified by:
getMoves in class Module
Returns:
An array of RatedMove objects.

getRequiredModuleList

public ModuleType[] getRequiredModuleList()
Get the modules that this module uses.

Specified by:
getRequiredModuleList in class Module
Returns:
An array of ModuleType objects.

getMoveNumber

public short getMoveNumber()
Get the move number. This is the number of the next move to be made. The handicap stones are not counted.

Specified by:
getMoveNumber in interface Board
Returns:
A short which is the move number.

makeMove

public void makeMove(Move move)
              throws IllegalMoveException,
                     InternalErrorException
Update this module with the move which has been made. This method is meant to be called by another module which wishes to add a move to the board.

Specified by:
makeMove in interface Board
Parameters:
move - The move to be made.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown is the operation fails for any reason.

makeMove

public void makeMove(Move move,
                     Module[] modules)
              throws IllegalMoveException,
                     InternalErrorException
Update this module with the move which has been made.

Specified by:
makeMove in class Module
Parameters:
move - The move to be made.
modules - The modules which this module requires.
Throws:
IllegalMoveException - Thrown if the move is illegal.
InternalErrorException - Thrown is the operation fails for any reason.

updateState

private void updateState(Move move)
Update the state variables as a result of the move.

Parameters:
move - The move which has been made.

isEndOfGame

public boolean isEndOfGame()
Determine if the last move ended the game. The game is over if the last move was a resignation, or if the last N consecutive moves were passes, where N is the value returned by numberOfPassesToEndGame().

Specified by:
isEndOfGame in interface Board
Returns:
true if the game is over, or false.

didSuicideOccur

public boolean didSuicideOccur()
Return true if the last move was a suicide, or false.

Specified by:
didSuicideOccur in interface Board
Returns:
true if the last move was a suicide, or false.

toString

public String toString()
Return a String representation of the board.

Overrides:
toString in class Object
Returns:
A String object which represents the state of the board.

clone

public Object clone()
Override the Object.clone() method.

Specified by:
clone in interface ModuleInterface
Overrides:
clone in class Module
Returns:
A BoardImpl object which is a copy of this one.