org.moyoman.helper.board.rules.agarules.agarulesimpl
Class AGARulesImpl

java.lang.Object
  |
  +--org.moyoman.helper.Helper
        |
        +--org.moyoman.helper.board.rules.RulesHelper
              |
              +--org.moyoman.helper.board.rules.agarules.AGARules
                    |
                    +--org.moyoman.helper.board.rules.agarules.agarulesimpl.AGARulesImpl
All Implemented Interfaces:
Cloneable, Component, Serializable

public class AGARulesImpl
extends AGARules

This class implements the AGARules interface to return the correct responses for the AGA rule set.

See Also:
Serialized Form

Field Summary
private static DebugType[] dt
          The debug types that this helper returns.
private  Stone ko
          The move which would cause an illegal retaking of the ko, or null.
private  Board lastBoard
          A Board object which represents the current state of the game.
private static ModuleType[] mt
          The modules that this helper requires.
private  HashSet occupied
          All of the Stone objects which are currently on the board.
private  HashSet suicide
          All of the Stone objects that would cause an illegal suicide on the next move.
private  HashSet superKo
          All of the Stone objects that would cause an illegal super ko on the next move.
(package private)  HashSet zobrist
          Long objects which are the Zobrist hashes for each previous board position.
 
Fields inherited from class org.moyoman.helper.Helper
 
Constructor Summary
AGARulesImpl(GameId gid, Mode mode, HelperName hname, Component parent)
          Create the AGARulesImpl object.
 
Method Summary
private  void addGroupToSet(Stone st, Set set, Color[][] stones)
          Add all of the stones of the same color and group as the specified stone to the set.
private  void assessKo(Board board)
          Determine if there is a ko, and set the ko variable.
private  void assessSuperKo(Board board)
           
 Object clone()
          Override the Object.clone() method.
private  void computeLegalAndIllegalMoves(Board board)
          Determine which moves are legal and illegal.
 boolean doCountPointsInSeki()
          Determine if points in a seki are counted as territory.
 Set findPrisoners(Board board)
          Find the set of prisoners to be removed from the board.
 boolean freePlacementOfHandicapStones()
          Determine if handicap stones are placed in a fixed pattern.
private  Stone[] getAdjacentStones(Color c, int x, int y, Color[][] stones)
          Get the stones immediately adjacent to this stone of the same color.
private  Stone[] getAdjacentStones(Stone st, Color[][] stones)
          Get the stones immediately adjacent to this stone of the same color.
 Debug[] getDebugInformation(DebugType[] types)
          Get the debug information for this helper.
 DebugType[] getDebugTypes()
          Get the debug types that this helper returns.
 Stone getKo()
          Return the move that would be an illegal retaking of the ko.
 float getKomi()
          Get the komi for an even game.
 short getLegalityStatus(NumberedStone ns, Board board)
          Determine if the move is legal or not.
private  Set getPrisoners(Stone st, Color[][] stones)
          Get the prisoners which are caused by playing the specified stone.
 ModuleType[] getRequiredModuleList()
          Get the module types that this helper requires.
 Rules getRules()
          Get the Rules object corresponding to AGA rules.
 Stone[] getSuicide()
          Get the stones which would be an illegal move because it would lead to suicide.
 Stone[] getSuperKo()
          Get all the stones which would cause an illegal recreation of the whole board position.
 boolean isBentFourDeadByRule()
          Determine if the bent four position is played out or not.
 boolean isLegalMove(NumberedStone ns, Board board)
          Determine if the move is a legal move.
private  boolean isSuicide(Stone st, Color[][] stones)
          Determine if the move would be suicide.
 boolean isSuicideAllowed()
          Determine if suicide is allowed.
private  boolean isSurrounded(Stone st, Color[][] stones)
          Determine if this stone is in a group with zero liberties.
 boolean isTerritoryScoring()
          Determine if territory or area scoring is used.
 void makeMove(Board board)
          Update this rules helper object with the current board position.
 boolean mustWhiteMoveLast()
          Determine if white must make the last move.
 short numberOfPassesToEndGame()
          Determine the number of consecutive passes to end the game.
 short superKoRule()
          Determine the rule regarding super ko.
 
Methods inherited from class org.moyoman.helper.Helper
checkTime, create, createHelper, debug, error, error, fatal, fatal, getAllHelpers, getHelper, getHelperName, getId, getMode, getModule, getParent, getScheduler, information, setTime, warning, warning
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dt

private static DebugType[] dt
The debug types that this helper returns.


mt

private static ModuleType[] mt
The modules that this helper requires.


suicide

private HashSet suicide
All of the Stone objects that would cause an illegal suicide on the next move.


superKo

private HashSet superKo
All of the Stone objects that would cause an illegal super ko on the next move.


occupied

private HashSet occupied
All of the Stone objects which are currently on the board.


ko

private Stone ko
The move which would cause an illegal retaking of the ko, or null.


zobrist

HashSet zobrist
Long objects which are the Zobrist hashes for each previous board position.


lastBoard

private Board lastBoard
A Board object which represents the current state of the game.

Constructor Detail

AGARulesImpl

public AGARulesImpl(GameId gid,
                    Mode mode,
                    HelperName hname,
                    Component parent)
             throws InternalErrorException
Create the AGARulesImpl object.

Parameters:
gid - The game id.
mode - The mode of the player.
hname - The name of this helper.
parent - The RulesHelper module.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Method Detail

doCountPointsInSeki

public boolean doCountPointsInSeki()
Determine if points in a seki are counted as territory.

Specified by:
doCountPointsInSeki in class RulesHelper
Returns:
true, since this is done under AGA rules.

freePlacementOfHandicapStones

public boolean freePlacementOfHandicapStones()
Determine if handicap stones are placed in a fixed pattern.

Specified by:
freePlacementOfHandicapStones in class RulesHelper
Returns:
false, since handicap stones are placed in a fixed pattern under AGA rules.

getKomi

public float getKomi()
Get the komi for an even game.

Specified by:
getKomi in class RulesHelper
Returns:
The float value for komi under AGA rules.

isBentFourDeadByRule

public boolean isBentFourDeadByRule()
Determine if the bent four position is played out or not.

Specified by:
isBentFourDeadByRule in class RulesHelper
Returns:
false, since this position is played out under AGA rules.

isSuicideAllowed

public boolean isSuicideAllowed()
Determine if suicide is allowed.

Specified by:
isSuicideAllowed in class RulesHelper
Returns:
false, since suicide is not allowed under AGA rules.

isTerritoryScoring

public boolean isTerritoryScoring()
Determine if territory or area scoring is used.

Specified by:
isTerritoryScoring in class RulesHelper
Returns:
true, since territory scoring is used under AGA rules.

mustWhiteMoveLast

public boolean mustWhiteMoveLast()
Determine if white must make the last move.

Specified by:
mustWhiteMoveLast in class RulesHelper
Returns:
true, since white must move last under AGA rules.

numberOfPassesToEndGame

public short numberOfPassesToEndGame()
Determine the number of consecutive passes to end the game. This method returns the number if mustWhiteMoveLast() return false. If it returns true, then the logic for dealing with that situation is outside of this method.

Specified by:
numberOfPassesToEndGame in class RulesHelper
Returns:
The short value 2, since that is the number of consecutive passes that ends the game.

superKoRule

public short superKoRule()
Determine the rule regarding super ko.

Specified by:
superKoRule in class RulesHelper
Returns:
The short Board.FORBIDDEN is returned, since whole board repetition is forbidden under AGA rules.

getSuicide

public Stone[] getSuicide()
Get the stones which would be an illegal move because it would lead to suicide.

Specified by:
getSuicide in class RulesHelper
Returns:
An array of Stone objects.

getKo

public Stone getKo()
Return the move that would be an illegal retaking of the ko.

Specified by:
getKo in class RulesHelper
Returns:
A Stone object, or null if there is no ko.

getSuperKo

public Stone[] getSuperKo()
Get all the stones which would cause an illegal recreation of the whole board position.

Specified by:
getSuperKo in class RulesHelper
Returns:
An array of Stone objects.

assessSuperKo

private void assessSuperKo(Board board)

isLegalMove

public boolean isLegalMove(NumberedStone ns,
                           Board board)
Determine if the move is a legal move.

Specified by:
isLegalMove in class RulesHelper
Parameters:
ns - The NumberedStone object which is the move.
board - The Board object with the current board position.
Returns:
true if the move is legal, or false.

getLegalityStatus

public short getLegalityStatus(NumberedStone ns,
                               Board board)
Determine if the move is legal or not.

Specified by:
getLegalityStatus in class RulesHelper
Parameters:
board - The Board object with the current board position. or the reason why it is illegal.
ns - The move being tested.
Returns:
A short which indicates if a move is legal,

makeMove

public void makeMove(Board board)
Update this rules helper object with the current board position. At the time that this method is called, the Board object has already been updated to the current position, so if the last move was made by black, board.getLastMove() will return that move, and board.getColorToMove() will return Color.WHITE.

Specified by:
makeMove in class RulesHelper
Parameters:
board - The Board object with the current board position.

findPrisoners

public Set findPrisoners(Board board)
Find the set of prisoners to be removed from the board.

Specified by:
findPrisoners in class RulesHelper
Parameters:
board - The Board object with the current board position with prisoners still present.
Returns:
A Set which contains the Stone objects which are the prisoners.

getRules

public Rules getRules()
Get the Rules object corresponding to AGA rules.

Specified by:
getRules in class RulesHelper
Returns:
The Rules.AGA object.

clone

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

Overrides:
clone in class Helper
Returns:
An AGARulesImpl object which is a clone of this one.

getDebugInformation

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

Specified by:
getDebugInformation in class Helper
Parameters:
types - The supported debug types.
Returns:
An array of Debug objects.

getDebugTypes

public DebugType[] getDebugTypes()
Get the debug types that this helper returns.

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

getRequiredModuleList

public ModuleType[] getRequiredModuleList()
Get the module types that this helper requires.

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

computeLegalAndIllegalMoves

private void computeLegalAndIllegalMoves(Board board)
Determine which moves are legal and illegal. This includes determining the reason why a move is illegal.

Parameters:
board - The Board object which contains the current board position.

assessKo

private void assessKo(Board board)
Determine if there is a ko, and set the ko variable.

Parameters:
board - The current board position.

getPrisoners

private Set getPrisoners(Stone st,
                         Color[][] stones)
Get the prisoners which are caused by playing the specified stone. There do not necessarily have to be any captures, in which case, the Set that is returned will have a size() of 0.

Parameters:
st - The stone which was played to cause the captures.
Returns:
A Set containing the Stone objects which were captured by the specified stone.

addGroupToSet

private void addGroupToSet(Stone st,
                           Set set,
                           Color[][] stones)
Add all of the stones of the same color and group as the specified stone to the set.

Parameters:
st - The stone for which adjacent stones are being found.
set - A Set which contains the adjacent stones found so far.

isSuicide

private boolean isSuicide(Stone st,
                          Color[][] stones)
Determine if the move would be suicide.

Parameters:
st - The stone in question.
Returns:
true if the move would be suicide, or false.

getAdjacentStones

private Stone[] getAdjacentStones(Color c,
                                  int x,
                                  int y,
                                  Color[][] stones)
Get the stones immediately adjacent to this stone of the same color.

Parameters:
c - The color of stone looked for.
x - The horizontal coordinate checked.
y - The vertical coordinate checked.
Returns:
An array of Stone objects which are the adjacent stones.

getAdjacentStones

private Stone[] getAdjacentStones(Stone st,
                                  Color[][] stones)
Get the stones immediately adjacent to this stone of the same color.

Parameters:
st - The stone in question.
Returns:
An array of Stone objects which are the adjacent stones.

isSurrounded

private boolean isSurrounded(Stone st,
                             Color[][] stones)
Determine if this stone is in a group with zero liberties. This method does not determine if any of the surrounding groups would be captured by this stone.

Parameters:
st - The stone in question.
Returns:
true if the stone is surrounded, or false.