org.moyoman.module.groups.groupsimpl
Class GroupsImpl

java.lang.Object
  |
  +--org.moyoman.module.Module
        |
        +--org.moyoman.module.groups.groupsimpl.GroupsImpl
All Implemented Interfaces:
Cloneable, Component, Groups, ModuleInterface, Serializable

public class GroupsImpl
extends Module
implements Groups

This module implements the Groups interface. It is responsible for maintaining the relation between the different SingleGroup objects.

See Also:
Serialized Form

Field Summary
private  ArrayList capturedGroups
          Each element is a SingleGroupImpl object which was captured by the last move.
private  ArrayList combinedGroups
          Each element is a SingleGroupImpl object that was combined with other groups by the last move.
private static DebugType[] dt
          The debug types that this module returns.
private  ArrayList groups
          Each element is a SingleGroupImpl object representing a group on the board.
private  Stone[] lastPrisoners
          The prisoners from the last move.
private  Stone lastStone
          The last stone placed on the board.
private  ModuleType[] mt
          The module types that this module requires.
private static RatedMove[] rm
          The ratings of moves by this module.
private  short statusVal
          One of the constants: Groups.ADD, Groups.UPDATE, Groups.COMBINE.
 
Fields inherited from class org.moyoman.module.Module
 
Fields inherited from interface org.moyoman.module.groups.Groups
ADD, COMBINE, SUICIDE, UPDATE
 
Constructor Summary
GroupsImpl(GameId id, ModuleName name)
          Create a new GroupsImpl object.
 
Method Summary
private  boolean adjacentHorizontal(SingleGroup sg1, SingleGroup sg2)
          Determine if the two groups overlap or are adjacent horizontally.
private  boolean adjacentPoints(Point pt1, Point pt2)
          Determine if two points are adjacent.
private  boolean adjacentVertical(SingleGroup sg1, SingleGroup sg2)
          Determine if the two groups overlap or are adjacent vertically.
 boolean areGroupsAdjacent(SingleGroup sg1, SingleGroup sg2)
          Return true if the two single groups have at least one stone touching.
 Object clone()
          Override the Object.clone() method.
protected  void error(Exception e)
          Provide an error method which SingleGroupImpl can also call.
 void generateMove(Module[] modules)
          Generate the rated moves.
 SingleGroup[] getAdjacentSingleGroupsOfOppositeColors(SingleGroup sg)
          Get all groups that are adjacent to this group of the opposing color.
 SingleGroup[] getCapturedSingleGroups()
          Get the groups that were captured by the last stone.
 SingleGroup[] getCombinedSingleGroups()
          Get the SingleGroups which were combined into a single group by the last stone played.
 Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
 DebugType[] getDebugTypes()
          Get the debug types which this module supports.
 RatedMove[] getMoves()
          Get the rated moves.
 SingleGroup getNewSingleGroup()
          Get the SingleGroup which contains the last stone played.
 ModuleType[] getRequiredModuleList()
          Return the modules that this module requires.
 SingleGroup getSingleGroup(Stone stone)
          Get the SingleGroup object which contains the stone.
 SingleGroup[] getSingleGroups()
          Get all of the SingleGroup objects.
 SingleGroup[] getSuicidedSingleGroups()
          Get the SingleGroup objects which died as a result of suicide on the last move.
 short getTotalSingleGroups()
          Return the total number of groups.
 SingleGroup getUpdatedSingleGroup()
          Get the SingleGroup which contains the last stone played.
 void makeMove(Move move, Module[] modules)
          Update this module with the last move.
private  boolean overlapHorizontal(SingleGroup sg1, SingleGroup sg2)
          Determine if the two groups overlap horizontally.
private  boolean overlapVertical(SingleGroup sg1, SingleGroup sg2)
          Determine if the two groups overlap vertically.
 short status()
          Get the status of the last move that was a stone.
 String toString()
          Return a String representation of this object.
 boolean wereGroupsCaptured()
          Determine if the last stone played captured any prisoners.
 
Methods inherited from class org.moyoman.module.Module
checkTime, create, createHelper, debug, 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, 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 returns.


mt

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


rm

private static RatedMove[] rm
The ratings of moves by this module.


groups

private ArrayList groups
Each element is a SingleGroupImpl object representing a group on the board.


combinedGroups

private ArrayList combinedGroups
Each element is a SingleGroupImpl object that was combined with other groups by the last move.


lastStone

private Stone lastStone
The last stone placed on the board.


lastPrisoners

private Stone[] lastPrisoners
The prisoners from the last move.


capturedGroups

private ArrayList capturedGroups
Each element is a SingleGroupImpl object which was captured by the last move.


statusVal

private short statusVal
One of the constants: Groups.ADD, Groups.UPDATE, Groups.COMBINE.

Constructor Detail

GroupsImpl

public GroupsImpl(GameId id,
                  ModuleName name)
           throws InternalErrorException
Create a new GroupsImpl object.

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

status

public short status()
Get the status of the last move that was a stone. Either a new group was added, a stone was added to a group, or two or more groups were combined. A pass does not change the value returned by this method.

Specified by:
status in interface Groups
Returns:
One of the constants: Groups.ADD, Groups.UPDATE, Groups.COMBINE.

wereGroupsCaptured

public boolean wereGroupsCaptured()
Determine if the last stone played captured any prisoners.

Specified by:
wereGroupsCaptured in interface Groups
Returns:
true if prisoners were captured, or false.

getSingleGroups

public SingleGroup[] getSingleGroups()
Get all of the SingleGroup objects.

Specified by:
getSingleGroups in interface Groups
Returns:
An array of SingleGroup objects.

getSingleGroup

public SingleGroup getSingleGroup(Stone stone)
                           throws NoSuchDataException
Get the SingleGroup object which contains the stone.

Specified by:
getSingleGroup in interface Groups
Parameters:
stone - The stone in question.
Returns:
A SingleGroup object.
Throws:
NoSuchDataException - Thrown if the stone is not in any groups.

getNewSingleGroup

public SingleGroup getNewSingleGroup()
                              throws NoSuchDataException
Get the SingleGroup which contains the last stone played. This method is only valid if status() returns Groups.ADD.

Specified by:
getNewSingleGroup in interface Groups
Returns:
A SingleGroup object.
Throws:
NoSuchDataException - Thrown if status() does not return Groups.ADD.

getUpdatedSingleGroup

public SingleGroup getUpdatedSingleGroup()
                                  throws NoSuchDataException
Get the SingleGroup which contains the last stone played. This method is only valid if status() returns Groups.UPDATE.

Specified by:
getUpdatedSingleGroup in interface Groups
Returns:
A SingleGroup object.
Throws:
NoSuchDataException - Thrown if status() does not return Groups.UPDATE.

getCombinedSingleGroups

public SingleGroup[] getCombinedSingleGroups()
                                      throws NoSuchDataException
Get the SingleGroups which were combined into a single group by the last stone played. This method is only valid if status() returns Groups.COMBINE. The SingleGroup objects returned are the ones from the previous move which are adjacent to the last stone, and one more SingleGroup object which contains the last stone by itself.

Specified by:
getCombinedSingleGroups in interface Groups
Returns:
An array of SingleGroup objects.
Throws:
NoSuchDataException - Thrown if status() does not return Groups.COMBINE.

getSuicidedSingleGroups

public SingleGroup[] getSuicidedSingleGroups()
                                      throws NoSuchDataException
Get the SingleGroup objects which died as a result of suicide on the last move.

Specified by:
getSuicidedSingleGroups in interface Groups
Returns:
An array of SingleGroup objects.
Throws:
NoSuchDataException - Thrown if Board.didSuicideOccur() returns false.

getTotalSingleGroups

public short getTotalSingleGroups()
Return the total number of groups.

Specified by:
getTotalSingleGroups in interface Groups
Returns:
A short which is the total number of groups.

generateMove

public void generateMove(Module[] modules)
Generate the rated moves.

Specified by:
generateMove in class Module
Parameters:
modules - The modules which this module uses.

getDebugInformation

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

Specified by:
getDebugInformation in class Module
Parameters:
types - The types of debug information requested.
Returns:
An array of Debug objects.

getDebugTypes

public DebugType[] getDebugTypes()
Get the debug types which this module supports.

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

getMoves

public RatedMove[] getMoves()
Get the rated moves.

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.

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

makeMove

public void makeMove(Move move,
                     Module[] modules)
              throws IllegalMoveException,
                     InternalErrorException
Update this module with the last move.

Specified by:
makeMove in class Module
Parameters:
move - The last move.
modules - The modules that this module needs.
IllegalMoveException
InternalErrorException

getAdjacentSingleGroupsOfOppositeColors

public SingleGroup[] getAdjacentSingleGroupsOfOppositeColors(SingleGroup sg)
Get all groups that are adjacent to this group of the opposing color.

Parameters:
sg - The single group.
Returns:
An array of SingleGroup objects.

getCapturedSingleGroups

public SingleGroup[] getCapturedSingleGroups()
Get the groups that were captured by the last stone.

Specified by:
getCapturedSingleGroups in interface Groups
Returns:
An array of SingleGroup objects.

areGroupsAdjacent

public boolean areGroupsAdjacent(SingleGroup sg1,
                                 SingleGroup sg2)
Return true if the two single groups have at least one stone touching. It is assumed that the two single groups are of opposite colors, otherwise, they would be one single group.

Parameters:
sg1 - A single group
Returns:
true if the two groups are adjacent, or false.

adjacentPoints

private boolean adjacentPoints(Point pt1,
                               Point pt2)
Determine if two points are adjacent.

Parameters:
pt1 - One of the points.
pt2 - The other point.
Returns:
true if the two points are adjacent, or false.

overlapHorizontal

private boolean overlapHorizontal(SingleGroup sg1,
                                  SingleGroup sg2)
Determine if the two groups overlap horizontally.

Parameters:
sg1 - One of the groups.
sg2 - The other group.
Returns:
true if the groups overlap horizontally, or false.

adjacentHorizontal

private boolean adjacentHorizontal(SingleGroup sg1,
                                   SingleGroup sg2)
Determine if the two groups overlap or are adjacent horizontally. This method always returns true if overlapHorizontal() returns true, but it also returns true if the groups do not overlap, but are adjacent horizontally.

Parameters:
sg1 - One of the groups.
sg2 - The other group.
Returns:
true if the groups overlap horizontally, or false.

overlapVertical

private boolean overlapVertical(SingleGroup sg1,
                                SingleGroup sg2)
Determine if the two groups overlap vertically.

Parameters:
sg1 - One of the groups.
sg2 - The other group.
Returns:
true if the groups overlap vertically, or false.

adjacentVertical

private boolean adjacentVertical(SingleGroup sg1,
                                 SingleGroup sg2)
Determine if the two groups overlap or are adjacent vertically. This method always returns true if overlapVertical() returns true, but it also returns true if the groups do not overlap, but are adjacent vertically.

Parameters:
sg1 - One of the groups.
sg2 - The other group.
Returns:
true if the groups overlap vertically, or false.

toString

public String toString()
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
A String which is a representation of this object.

error

protected void error(Exception e)
Provide an error method which SingleGroupImpl can also call.

Overrides:
error in class Module
Parameters:
e - The exception to be logged.

clone

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

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