org.moyoman.helper.board.rules.rulesimpl
Class RulesImpl

java.lang.Object
  |
  +--org.moyoman.helper.Helper
        |
        +--org.moyoman.helper.board.rules.RulesHelper
              |
              +--org.moyoman.helper.board.rules.rulesimpl.RulesImpl
All Implemented Interfaces:
Cloneable, Component, Serializable

public class RulesImpl
extends RulesHelper

This class determines what type of rules helper is to be used. The Board module can use this class, and then this class acts as a proxy to pass through the calls to the rules helper of the appropriate rules type, such as Chinese.

See Also:
Serialized Form

Field Summary
private  RulesHelper rh
          The RulesHelper object for the specific rules set for this game.
 
Fields inherited from class org.moyoman.helper.Helper
 
Constructor Summary
RulesImpl(GameId gid, Mode mode, HelperName hname, Component parent)
          Create the RulesImpl object.
 
Method Summary
 Object clone()
          Override the Object.clone() method.
 boolean doCountPointsInSeki()
          Determine if territory in a seki is counted.
 Set findPrisoners(Board board)
          Find the prisoners which need to be removed from the board.
 boolean freePlacementOfHandicapStones()
          Determine if handicap stones must be place in a set pattern.
 Debug[] getDebugInformation(DebugType[] dt)
          Get the debug information for this helper.
 DebugType[] getDebugTypes()
          Get the debug types that this helper supports.
 Stone getKo()
          Get the move that would be illegal due to immediately retaking the ko.
 float getKomi()
          Get the komi.
 short getLegalityStatus(NumberedStone ns, Board board)
          Determine the status of the given move.
 ModuleType[] getRequiredModuleList()
          Get the modules which this helper requires.
 Rules getRules()
          Get the rules for this game.
 Stone[] getSuicide()
          Get the moves which would be illegal due to suicide on the next move.
 Stone[] getSuperKo()
          Get the move that would be illegal because of recreating a whole board position.
 boolean isBentFourDeadByRule()
          Determine if the bent four group is dead by rule, or must be played out.
 boolean isLegalMove(NumberedStone ns, Board board)
          Determine if the given move is legal.
 boolean isSuicideAllowed()
          Determine if suicide is allowed.
 boolean isTerritoryScoring()
          Determine if territory (Japanese) or area (Chinese) scoring is used.
 void makeMove(Board board)
          Update the RulesHelper with the latest move.
 boolean mustWhiteMoveLast()
          Determine if white must move last.
 short numberOfPassesToEndGame()
          Determine the number of consecutive passes that ends the game.
 short superKoRule()
          Determine the type of super ko rule which is in effect.
 
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

rh

private RulesHelper rh
The RulesHelper object for the specific rules set for this game.

Constructor Detail

RulesImpl

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

Parameters:
gid - The game id
mode - The mode of the game.
hname - The helper name for the specific rules set.
parent - The Board module.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.
Method Detail

doCountPointsInSeki

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

Specified by:
doCountPointsInSeki in class RulesHelper
Returns:
true if the territory in a seki is counted, or false.

freePlacementOfHandicapStones

public boolean freePlacementOfHandicapStones()
Determine if handicap stones must be place in a set pattern.

Specified by:
freePlacementOfHandicapStones in class RulesHelper
Returns:
false if the handicap stones must be placed in a set pattern, or true.

getKomi

public float getKomi()
Get the komi.

Specified by:
getKomi in class RulesHelper
Returns:
A float which is the komi.

isBentFourDeadByRule

public boolean isBentFourDeadByRule()
Determine if the bent four group is dead by rule, or must be played out.

Specified by:
isBentFourDeadByRule in class RulesHelper
Returns:
true if the bent four group is dead by rule, or false.

isSuicideAllowed

public boolean isSuicideAllowed()
Determine if suicide is allowed.

Specified by:
isSuicideAllowed in class RulesHelper
Returns:
true if suicide is allowed, or false.

isTerritoryScoring

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

Specified by:
isTerritoryScoring in class RulesHelper
Returns:
true if territory scoring is used, or false.

mustWhiteMoveLast

public boolean mustWhiteMoveLast()
Determine if white must move last. Each time that a player passes, he must give his opponent a prisoner. If this method is true, then if black makes a pass that would end the game, black must still pass after that.

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

numberOfPassesToEndGame

public short numberOfPassesToEndGame()
Determine the number of consecutive passes that ends the game.

Specified by:
numberOfPassesToEndGame in class RulesHelper
Returns:
A short which is the number of consecutive passes that ends the game.

superKoRule

public short superKoRule()
Determine the type of super ko rule which is in effect.

Specified by:
superKoRule in class RulesHelper
Returns:
A short which is one of:
  1. Board.ALLOWED
  2. Board.DRAW
  3. Board.FORBIDDEN

getSuicide

public Stone[] getSuicide()
Get the moves which would be illegal due to suicide on the next move. Note that if isSuicideAllowed() is true, then the array returned by this method will always be of size 0.

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

getKo

public Stone getKo()
Get the move that would be illegal due to immediately retaking the ko.

Specified by:
getKo in class RulesHelper
Returns:
The stone which is the illegal move, or null if there is no ko.

getSuperKo

public Stone[] getSuperKo()
Get the move that would be illegal because of recreating a whole board position. If superKoRule() would return Board.ALLOWED, then this method would always return an array of size 0.

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

isLegalMove

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

Specified by:
isLegalMove in class RulesHelper
Parameters:
ns - The move being tested.
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 the status of the given move. If the move is illegal, then it returns the reason why it is illegal.

Specified by:
getLegalityStatus in class RulesHelper
Parameters:
ns - The move being tested.
board - The Board object with the current board position.
Returns:
A short which is one of the following possibilities:
  1. Board.LEGAL
  2. Board.KO
  3. Board.SUICIDE
  4. Board.SUPERKO
  5. Board.FILLED
  6. Board.WRONG_COLOR

getDebugInformation

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

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

getDebugTypes

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

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

makeMove

public void makeMove(Board board)
Update the RulesHelper with the latest move.

Specified by:
makeMove in class RulesHelper
Parameters:
board - The Board object which contains the state of the board.

findPrisoners

public Set findPrisoners(Board board)
Find the prisoners which need to be removed from the board.

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

getRequiredModuleList

public ModuleType[] getRequiredModuleList()
Get the modules which this helper requires.

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

getRules

public Rules getRules()
Get the rules for this game.

Specified by:
getRules in class RulesHelper
Returns:
A Rules object.

clone

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

Overrides:
clone in class Helper
Returns:
A RulesImpl object which is a clone of this one.