org.moyoman.module.endgame.simpleendgame
Class SimpleEndgame

java.lang.Object
  |
  +--org.moyoman.module.Module
        |
        +--org.moyoman.module.endgame.simpleendgame.SimpleEndgame
All Implemented Interfaces:
Cloneable, Component, Endgame, ModuleInterface, Serializable

public class SimpleEndgame
extends Module
implements Endgame

This module implements the Endgame interface. It is responsible for finding sequences of moves at the end of the game.

See Also:
Serialized Form

Field Summary
private static DebugType[] dt
          The debug types that this module supports.
private  boolean isGenerated
          This flag is used to determine when to clear variables set by generateMove().
private  Board lastBoard
          The last board obtained from generateMove().
private  MoveDescriptorForest mdf
          The MoveDescriptorForest object containing sequences of moves.
private  ModuleType[] mt
          The modules that this module requires.
private  RatedMove[] rm
          The moves that were rated by this module.
private  boolean sequenceFlag
          This flag is used to determine if a call to getSequences() is valid.
 
Fields inherited from class org.moyoman.module.Module
 
Fields inherited from interface org.moyoman.module.endgame.Endgame
CONFIDENCE
 
Constructor Summary
SimpleEndgame(GameId id, ModuleName name)
          Create the SimpleEndgame object.
 
Method Summary
private  void addRatedMove(Geometry geo, Stone target, short num, float val, HashMap rm)
          Add rated moves to the HashMap if they are not in the convex hull.
private  boolean clearHorizontalPathToEdge(Stone st, Board board)
          Determine if the stone has a clear path to the nearest horizontal edge.
private  boolean clearVerticalPathToEdge(Stone st, Board board)
          Determine if there is a clear path from the stone to the vertical edge.
 Object clone()
          Clone the module.
private  void evaluateMoves(Board board, Geometry geo, ArrayList al, Color color, short moveNumber, boolean isHorizontal, HashMap ratedMoves)
          Evaluate the moves in the list, and rate them accordingly.
private  void generateMDF()
          Generate the MoveDescriptorForest object describing sequences of moves.
 void generateMove(Module[] modules)
          Generate the move for this module.
 Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
 DebugType[] getDebugTypes()
          Return the types of debug information that this module supports.
 RatedMove[] getMoves()
          Return the moves generated by the module.
 ModuleType[] getRequiredModuleList()
          Return the modules that this module requires to perform its task.
 MoveDescriptorForest getSequences()
          Get sequences of moves that might occur in endgame play.
private  boolean isCloseToHorizontalEdge(Stone st, Board board)
          Determine if a stone is close to a horizontal edge.
private  boolean isCloseToVerticalEdge(Stone st, Board board)
          Determine if a stone is close to a vertical edge.
 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

dt

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


mt

private ModuleType[] mt
The modules that this module requires.


rm

private RatedMove[] rm
The moves that were rated by this module.


lastBoard

private Board lastBoard
The last board obtained from generateMove().


mdf

private MoveDescriptorForest mdf
The MoveDescriptorForest object containing sequences of moves.


isGenerated

private boolean isGenerated
This flag is used to determine when to clear variables set by generateMove().


sequenceFlag

private boolean sequenceFlag
This flag is used to determine if a call to getSequences() is valid.

Constructor Detail

SimpleEndgame

public SimpleEndgame(GameId id,
                     ModuleName name)
              throws InternalErrorException
Create the SimpleEndgame object.

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.

generateMDF

private void generateMDF()
Generate the MoveDescriptorForest object describing sequences of moves.


evaluateMoves

private void evaluateMoves(Board board,
                           Geometry geo,
                           ArrayList al,
                           Color color,
                           short moveNumber,
                           boolean isHorizontal,
                           HashMap ratedMoves)
Evaluate the moves in the list, and rate them accordingly. It is possible that the same move will get rated twice. There should only be one RatedMove object for each Stone object.

Parameters:
board - The Board module.
geo - The Geometry module.
al - Each element is a stone to be rated.
color - The color of the side to move.
moveNumber - The move number of the next move.
isHorizontal - indicates if the edge examined is a horizontal or vertical one.
ratedMoves - The rated moves are added to this HashMap as the value, the key is the corresponding Stone object.

addRatedMove

private void addRatedMove(Geometry geo,
                          Stone target,
                          short num,
                          float val,
                          HashMap rm)
Add rated moves to the HashMap if they are not in the convex hull.

Parameters:
geo - The Geometry module.
target - The position of the move.
num - The move number
val - The rating of the move.
rm - The HashMap to add the Stone, RatedMove pair to.

isCloseToHorizontalEdge

private boolean isCloseToHorizontalEdge(Stone st,
                                        Board board)
Determine if a stone is close to a horizontal edge. Stones which are on the horizontal edge fail this test. This method does not consider if there are stones between it and the edge, just the distance.

Parameters:
st - The stone being tested.
board - The Board module.
Returns:
true if the stone is close to the horizontal edge, or false.

isCloseToVerticalEdge

private boolean isCloseToVerticalEdge(Stone st,
                                      Board board)
Determine if a stone is close to a vertical edge. This method does not consider if there are stones between it and the edge, just the distance.

Parameters:
st - The stone being tested.
board - The Board module.
Returns:
true if the stone is close to the vertical edge, or false.

clearHorizontalPathToEdge

private boolean clearHorizontalPathToEdge(Stone st,
                                          Board board)
Determine if the stone has a clear path to the nearest horizontal edge.

Parameters:
st - The stone being tested.
board - The Board module.
Returns:
true if the stone has a clear path, or false.

clearVerticalPathToEdge

private boolean clearVerticalPathToEdge(Stone st,
                                        Board board)
Determine if there is a clear path from the stone to the vertical edge.

Parameters:
st - The stone being tested.
board - The Board module.
Returns:
true if there is a clear path, or false.

getDebugInformation

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

Specified by:
getDebugInformation in class Module
Parameters:
types - Only return a subset 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.

getSequences

public MoveDescriptorForest getSequences()
                                  throws NoSuchDataException
Get sequences of moves that might occur in endgame play. The sequences are not considered to be equally good. Use the getMoves() method to determine which move this module considers to be best.

Specified by:
getSequences in interface Endgame
Returns:
A MoveDescriptorForest object which contains sequences of moves for endgame play.
Throws:
NoSuchDataException - Thrown if the last move made was not generated by this player.

clone

public Object clone()
Clone the module.

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