org.moyoman.module
Class Module

java.lang.Object
  |
  +--org.moyoman.module.Module
All Implemented Interfaces:
Cloneable, Component, ModuleInterface, Serializable
Direct Known Subclasses:
BoardImpl, DameImpl, GeometryImpl, GroupsImpl, IgoFuseki, IgoProverbs, JosekiImpl, LadderImpl, LGImpl, RandomImpl, SimpleBigPoint, SimpleEndgame, SimpleFuseki, SimpleMoveGenerator, SimpleSafety, SimpleShape, SimpleTactics, TacticsImpl

public abstract class Module
extends Object
implements Component, ModuleInterface

The base class for all modules in the system. This class is probably the most crucial one for the developer who wants to contribute their own implementation of a module.

See Also:
Serialized Form

Field Summary
private  DebugType[] debugTypes
          The debug types that this module supports.
private  HashMap helpers
          The name is a HelperType object, and the value is the Helper object.
private  GameId id
          The game that this module is associated with.
private  ModuleName moduleName
          The name of the module.
private  float time
           
 
Constructor Summary
protected Module(GameId id, ModuleName name)
          Create the Module object.
 
Method Summary
protected  float checkTime()
          Return information on how the game as a whole is doing on time.
 Object clone()
          Clone the module.
static Module create(GameId id, ModuleName name)
          Create a Module object.
protected  Helper createHelper(String name)
          Create a helper for this module
 void debug(String msg)
          Log a debug message in the module.
protected  void error(Exception e)
          Log an error in the module.
 void error(String msg)
          Log an error in the module.
protected  void fatal(Exception e)
          Log a fatal error in the module.
 void fatal(String msg)
          Log a fatal error in the module.
private  String formatMessage(String msg)
          Format the message string so that it can be easily parsed.
abstract  void generateMove(Module[] modules)
          Generate the move for this module.
protected  Helper[] getAllHelpers()
          Get all of the helpers for this module.
abstract  Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
abstract  DebugType[] getDebugTypes()
          Return the types of debug information that this module supports.
protected  Helper getHelper(HelperType ht)
          Get the helper of a specific type.
protected  GameId getId()
          Get the id that this module is associated with.
protected  float getKomi()
           
static Module getModule(Module[] modules, ModuleType type)
          Return the module from the array that is of the specific type.
 ModuleName getModuleName()
          Return the ModuleName object.
abstract  RatedMove[] getMoves()
          Return the moves generated by the module.
abstract  ModuleType[] getRequiredModuleList()
          Return the modules that this module requires to perform its task.
 Scheduler getScheduler()
          Get a Scheduler object for this module.
 void information(String msg)
          Log an information message in the module.
private  String logPrefix()
          Get the string that is to be logged before the actual message.
abstract  void makeMove(Move move, Module[] modules)
          Update the internal data structures of this module with the new move.
 void setTime(float t)
          Set the time for this module.
protected  void warning(Exception e)
          Log a warning in the module.
 void warning(String msg)
          Log a warning in the module.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugTypes

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


id

private GameId id
The game that this module is associated with.


time

private float time

moduleName

private ModuleName moduleName
The name of the module.


helpers

private HashMap helpers
The name is a HelperType object, and the value is the Helper object.

Constructor Detail

Module

protected Module(GameId id,
                 ModuleName name)
          throws InternalErrorException
Create the Module object.

Parameters:
id - The id of the game.
name - The name of the module.
Throws:
InternalErrorException - Thrown if anything goes wrong.
Method Detail

create

public static final Module create(GameId id,
                                  ModuleName name)
                           throws InternalErrorException
Create a Module object.

Parameters:
id - The id of the game.
name - The name of the module.
Returns:
The Module object.
Throws:
InternalErrorException - Thrown if anything goes wrong. Should never happen except during development.

checkTime

protected float checkTime()
Return information on how the game as a whole is doing on time. There is no per-module resource monitor. This method should be used when trying to determine how much processing to do. In this way, a game can reliably be played in a certain amount of time on machines which differ widely in processor speed and memory.

Returns:
This value can vary between -1.0 and 1.0. A value of 1.0 indicates that the game is way ahead on time, -1.0 would indicate severe time problems, and 0.0 indicates that the game is on schedule.

getKomi

protected float getKomi()

clone

public Object clone()
Clone the module. This method overrides the one in Object. Cloning modules is an important requirement for the system to function correctly. The derived class of Module must override this method. It may be as straightforward as calling super.clone(). Consult any Java textbook for more details. If you are not sure, ask for help.

Specified by:
clone in interface ModuleInterface
Overrides:
clone in class Object
Returns:
The cloned Module object.

setTime

public void setTime(float t)
             throws IllegalArgumentException
Set the time for this module. This value represents the time for the game as a whole, not the particular module.

Parameters:
t - The time to be set.
Throws:
IllegalArgumentException - Thrown if t is outside the range of -1.0 to 1.0.

getScheduler

public final Scheduler getScheduler()
Get a Scheduler object for this module. The Scheduler object contains all objects terminating with one that is the same type as this object. This allows the module to do search based processing.

Specified by:
getScheduler in interface ModuleInterface
Returns:
The Scheduler object.

generateMove

public abstract void generateMove(Module[] modules)
                           throws InternalErrorException
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.

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.
InternalErrorException

getDebugInformation

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

Parameters:
types - The debug types that the caller knows how to handle.
Returns:
The debug information that this module supports.

getDebugTypes

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

Returns:
The types of debug information that this module supports.

getId

protected final GameId getId()
Get the id that this module is associated with.

Returns:
The id of the game.

getModuleName

public final ModuleName getModuleName()
Return the ModuleName object.

Returns:
The ModuleName object.

getModule

public static final Module getModule(Module[] modules,
                                     ModuleType type)
                              throws NoSuchDataException
Return the module from the array that is of the specific type. The generateMove() and makeMove() methods both pass an array of modules, from which the user will need to get the desired one.

Parameters:
modules - An array of module objects
type - The module type being searched for.
Returns:
The desired module.
Throws:
NoSuchDataException - An exception is thrown if the desired module type is not present.

getMoves

public abstract 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
Returns:
An array of RatedMove objects.

getRequiredModuleList

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

Returns:
An array of module types that the module requires.

makeMove

public abstract void makeMove(Move move,
                              Module[] modules)
                       throws IllegalMoveException,
                              InternalErrorException
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. If the module is stateless, then this method will only do minimal work. See org.moyoman.module.random.randomimpl.RandomImpl for an example of this.

Parameters:
move - The move that was just made.
modules - The modules that this method needs to perform its job.
Throws:
Exception - Thrown if the move is illegal for some reason.
IllegalMoveException
InternalErrorException

getAllHelpers

protected Helper[] getAllHelpers()
Get all of the helpers for this module.

Returns:
An array of Helper objects.

getHelper

protected Helper getHelper(HelperType ht)
                    throws NoSuchDataException
Get the helper of a specific type.

Parameters:
ht - The helper type to be retrieved.
Returns:
A Helper object.
Throws:
NoSuchDataException - Thrown if there is no helper of that type.

createHelper

protected Helper createHelper(String name)
                       throws NoSuchDataException,
                              InternalErrorException
Create a helper for this module

Parameters:
name - The name of the helper.
Returns:
A Helper object.
Throws:
NoSuchDataException - Thrown if the name does not correspond to a valid helper type.
InternalErrorException - Thrown if the operation fails for any reason.

fatal

protected void fatal(Exception e)
Log a fatal error in the module. Eventually, calling this method should result in this module being terminated, and another module of the same type replacing it.

Parameters:
e - The exception that was thrown.

error

protected void error(Exception e)
Log an error in the module.

Parameters:
e - The exception that was thrown.

warning

protected void warning(Exception e)
Log a warning in the module.

Parameters:
e - The exception that was thrown.

fatal

public void fatal(String msg)
Log a fatal error in the module. Eventually, calling this method should result in this module being terminated, and another module of the same type replacing it.

Parameters:
msg - The message to be logged.

error

public void error(String msg)
Log an error in the module.

Parameters:
msg - The message to be logged.

warning

public void warning(String msg)
Log a warning in the module.

Parameters:
msg - The message to be logged.

information

public void information(String msg)
Log an information message in the module.

Parameters:
msg - The message to be logged.

debug

public void debug(String msg)
Log a debug message in the module.

Parameters:
msg - The message to be logged.

logPrefix

private String logPrefix()
Get the string that is to be logged before the actual message.

Returns:
A String which appears at the beginning of each log message.

formatMessage

private String formatMessage(String msg)
Format the message string so that it can be easily parsed.

Parameters:
msg - The message.
Returns:
A String in standard format.