org.moyoman.module.safety.simplesafety
Class SimpleSafety

java.lang.Object
  |
  +--org.moyoman.module.Module
        |
        +--org.moyoman.module.safety.simplesafety.SimpleSafety
All Implemented Interfaces:
Cloneable, Component, ModuleInterface, Safety, Serializable

public class SimpleSafety
extends Module
implements Safety

This module implements the Safety interface. Its job is to determine the safety of each loose group on the board. By necessity, this is a very simplistic analysis, which can be refined by subsequent modules.

See Also:
Serialized Form

Field Summary
private static float ADEQUATESAFETY
          Groups which are rated more safe than this do not need any defending.
private  Board board
          The Board module which this module uses.
private static DebugType[] dt
          The debug types which this module supports.
private  Geometry geometry
          The Geometry module which this module uses.
private  boolean isGenerated
          This is true after generateMove() is called, but before makeMove() is called.
private  LooseGroups lg
          The LooseGroups module which this module uses.
private static float MINSAFETY
          The minimum safety required for a group to be considered worth saving.
private  ModuleType[] mt
          The types of modules which this module requires.
private  RatedMove[] rm
          The rated move which the generateMove() method produces.
private  HashMap safety
          The key is a LooseGroup, and the value is a Float.
 
Fields inherited from class org.moyoman.module.Module
 
Fields inherited from interface org.moyoman.module.safety.Safety
CONFIDENCE
 
Constructor Summary
SimpleSafety(GameId id, ModuleName name)
          Create the SimpleSafety module.
 
Method Summary
 Object clone()
          Override the Object.clone() method.
private static float computeSafety(SingleLooseGroup slg, Board b, LooseGroups lg, Geometry geo)
          Compute the safety for a loose group.
private  RatedMove[] evaluate(Board b, LooseGroups lg, Geometry geo)
          Determine the safety of each loose group on the board, and produce rated moves.
 void generateMove(Module[] modules)
          Generate the move for this module.
private  Set getBoundaryPoints(SingleLooseGroup slg, double strength, Board b, Geometry geo)
          Get the points of approximately equal distance between the loose group and other loose groups.
 Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
 DebugType[] getDebugTypes()
          Return the types of debug information that this module supports.
private  void getExtendingMoves(SingleLooseGroup curr, double strength, Board b, Geometry geo, int fcount, int ecount, HashMap moves)
          Find those moves which extends into the points closest to another loose group.
 RatedMove[] getMoves()
          Return the moves generated by the module.
 ModuleType[] getRequiredModuleList()
          Return the modules that this module requires to perform its task.
 float getSafety(SingleLooseGroup slg)
          Get the safety for a loose group.
private  double getStrength(SingleLooseGroup slg)
          Get the strength of a loose group.
 void makeMove(Move move, Module[] modules)
          Update the internal data structures of this module with the new move.
 
Methods inherited from class org.moyoman.module.Module
checkTime, create, createHelper, debug, error, error, fatal, fatal, getAllHelpers, getHelper, getId, getKomi, getModule, getModuleName, getScheduler, information, setTime, warning, warning
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.moyoman.module.ModuleInterface
getScheduler
 

Field Detail

MINSAFETY

private static final float MINSAFETY
The minimum safety required for a group to be considered worth saving.

See Also:
Constant Field Values

ADEQUATESAFETY

private static final float ADEQUATESAFETY
Groups which are rated more safe than this do not need any defending.

See Also:
Constant Field Values

dt

private static DebugType[] dt
The debug types which this module supports.


mt

private ModuleType[] mt
The types of modules which this module requires.


rm

private RatedMove[] rm
The rated move which the generateMove() method produces.


board

private Board board
The Board module which this module uses.


geometry

private Geometry geometry
The Geometry module which this module uses.


lg

private LooseGroups lg
The LooseGroups module which this module uses.


safety

private HashMap safety
The key is a LooseGroup, and the value is a Float.


isGenerated

private boolean isGenerated
This is true after generateMove() is called, but before makeMove() is called.

Constructor Detail

SimpleSafety

public SimpleSafety(GameId id,
                    ModuleName name)
             throws InternalErrorException
Create the SimpleSafety module.

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

generateMove

public void generateMove(Module[] modules)
Generate the move for this module. The side effect of calling this method is that an array of RatedMove objects is stored which is returned by the getMoves() method.

Specified by:
generateMove in class Module
Parameters:
modules - An array of modules which this module needs in order to perform its work. Those modules reflect the current state of the board but are copies of the actual modules, so this method is free to manipulate them.

evaluate

private RatedMove[] evaluate(Board b,
                             LooseGroups lg,
                             Geometry geo)
Determine the safety of each loose group on the board, and produce rated moves. Rated moves are produced based on the safety of each of the loose groups.

Parameters:
b - The Board module.
lg - The LooseGroups module.
geo - The Geometry module.
Returns:
An array of RatedMove objects.

getStrength

private double getStrength(SingleLooseGroup slg)
Get the strength of a loose group.

Parameters:
slg - The loose group.
Returns:
A double which is the strength of this group.

getExtendingMoves

private void getExtendingMoves(SingleLooseGroup curr,
                               double strength,
                               Board b,
                               Geometry geo,
                               int fcount,
                               int ecount,
                               HashMap moves)
Find those moves which extends into the points closest to another loose group. These moves may be offensive in the case of extending towards an opponents group, or defensive in the case of extending towards a friendly group.

Parameters:
curr - The loose group for which the moves are found.
strength - The strength of this group.
b - The Board module
geo - The Geometry module
fcount - The number of friendly loose groups on the board.
ecount - The number of enemy loose groups on the board.

getBoundaryPoints

private Set getBoundaryPoints(SingleLooseGroup slg,
                              double strength,
                              Board b,
                              Geometry geo)
Get the points of approximately equal distance between the loose group and other loose groups. This method needs to be more sophisticated than merely taking those points of equal distance. For example, for two rows of stones with two empty rows in between, there are no points equally distant. Also, the strength of the loose group affects the depth of this boundary area.

Parameters:
slg - The loose group.
strength - The strength of the loose group.
b - The Board module.
geo - The Geometry module.
Returns:
A Set containing Point objects which are the boundary points.

getDebugInformation

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

Specified by:
getDebugInformation in class Module
Parameters:
types - Only return Debug objects that are one of the debug types in this array.
Returns:
The debug information that this module supports.

getDebugTypes

public DebugType[] getDebugTypes()
Return the types of debug information that this module supports.

Specified by:
getDebugTypes in class Module
Returns:
The types of debug information that this module supports.

getMoves

public RatedMove[] getMoves()
Return the moves generated by the module. Note that both good and bad moves can be returned.

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

getRequiredModuleList

public ModuleType[] getRequiredModuleList()
Return the modules that this module requires to perform its task.

Specified by:
getRequiredModuleList in class Module
Returns:
An array of module types that the module requires.

makeMove

public void makeMove(Move move,
                     Module[] modules)
Update the internal data structures of this module with the new move. Note that this method is called both when the client makes a move, and when the server makes a move.

Specified by:
makeMove in class Module
Parameters:
move - The move that was just made.
modules - The modules that this method needs to perform its job.

computeSafety

private static float computeSafety(SingleLooseGroup slg,
                                   Board b,
                                   LooseGroups lg,
                                   Geometry geo)
Compute the safety for a loose group.

Parameters:
slg - The loose group.
Returns:
A float between 0.0f and 1.0f which is the safety of the group.

getSafety

public float getSafety(SingleLooseGroup slg)
Get the safety for a loose group. The difference between this method and computeSafety() is that computeSafety() always recomputes the value, while this method uses the cached value if available.

Specified by:
getSafety in interface Safety
Parameters:
slg - The loose group in question.
Returns:
A float which is the safety of the group.

clone

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

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