org.moyoman.module.groups.groupsimpl
Class SingleGroupImpl

java.lang.Object
  |
  +--org.moyoman.module.groups.groupsimpl.SingleGroupImpl
All Implemented Interfaces:
Cloneable, Serializable, SingleGroup

public class SingleGroupImpl
extends Object
implements SingleGroup, Cloneable, Serializable

This class implements the SingleGroup interface. It represents a set of stones which are captured as one unit.

See Also:
Serialized Form

Field Summary
private  Color color
          The color of the group.
private  GroupsImpl groups
          The GroupsImpl object.
private  HashSet liberties
          The empty Point objects which are the liberties of the group.
private  int maxx
          The maximum horizontal value of any stone in the group.
private  int maxy
          The maximum vertical value of any stone in the group.
private  int minx
          The minimum horizontal value of any stone in the group.
private  int miny
          The minimum vertical value of any stone in the group.
private  HashSet opponent
          Stone objects of the opposite color to the group which are directly adjacent.
private  HashSet stones
          The Stone objects which make up this group.
 
Constructor Summary
protected SingleGroupImpl(Stone s, Board board, GroupsImpl g)
          Create the new SingleGroupImpl object.
 
Method Summary
 Object clone()
          Override the Object.clone() method.
 Stone[] getAdjacentOpponentStones()
          Get all of the opponents stones adjacent to this group.
 Stone getAnyStone()
          Return one of the stones in the group.
 Color getColor()
          Get the color of this group.
 Point[] getLiberties()
          Get the points which are the liberties of this group.
 int getMaxX()
          Return the largest horizontal coordinate.
 int getMaxY()
          Return the largest vertical coordinate.
 int getMinX()
          Return the smallest horizontal coordinate.
 int getMinY()
          Return the smallest vertical coordinate.
 Stone[] getStones()
          Return the stones in the group.
 short getTotalLiberties()
          Get the total number of liberties for this group.
 short getTotalStones()
          Return the total number of stones in this group.
 boolean isInSingleGroup(Stone stone)
          Determine if the stone is in this group.
 boolean isLibertyOfSingleGroup(Point pt)
          Determine if the point is a liberty of this group.
 void recompute(Board board)
          Recompute the liberties and opponents for this group.
 String toString()
          Get a String representation of this object.
protected  void update(SingleGroupImpl sgi, Board board)
          Add the stones from a group to this one.
protected  void update(Stone s, Board board)
          Add the stone to this group.
private  void updateBounds(Stone s)
          Update the bounding box for this group.
private  void updateLibertiesAndOpponents(Stone s, Board board)
          Update the liberties and opponent data structures.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

stones

private HashSet stones
The Stone objects which make up this group.


liberties

private HashSet liberties
The empty Point objects which are the liberties of the group.


opponent

private HashSet opponent
Stone objects of the opposite color to the group which are directly adjacent.


color

private Color color
The color of the group.


minx

private int minx
The minimum horizontal value of any stone in the group.


maxx

private int maxx
The maximum horizontal value of any stone in the group.


miny

private int miny
The minimum vertical value of any stone in the group.


maxy

private int maxy
The maximum vertical value of any stone in the group.


groups

private GroupsImpl groups
The GroupsImpl object.

Constructor Detail

SingleGroupImpl

protected SingleGroupImpl(Stone s,
                          Board board,
                          GroupsImpl g)
Create the new SingleGroupImpl object.

Parameters:
s - The Stone which is the new group.
Method Detail

update

protected void update(Stone s,
                      Board board)
Add the stone to this group.

Parameters:
s - The Stone to be added to the group.

updateLibertiesAndOpponents

private void updateLibertiesAndOpponents(Stone s,
                                         Board board)
Update the liberties and opponent data structures.

Parameters:
s - The Stone to be added to the group.

update

protected void update(SingleGroupImpl sgi,
                      Board board)
Add the stones from a group to this one. This method would be called if the last move caused two or more groups to become a single group.


updateBounds

private void updateBounds(Stone s)
Update the bounding box for this group.


isInSingleGroup

public boolean isInSingleGroup(Stone stone)
Determine if the stone is in this group.

Specified by:
isInSingleGroup in interface SingleGroup
Parameters:
stone - The Stone being checked.
Returns:
true if the stone is in the group, or false.

isLibertyOfSingleGroup

public boolean isLibertyOfSingleGroup(Point pt)
Determine if the point is a liberty of this group.

Specified by:
isLibertyOfSingleGroup in interface SingleGroup
Parameters:
pt - The Point being checked.
Returns:
true if the point is a liberty of the group, or false.

getAnyStone

public Stone getAnyStone()
Return one of the stones in the group.

Specified by:
getAnyStone in interface SingleGroup
Returns:
A Stone object which is in the group.

getStones

public Stone[] getStones()
Return the stones in the group.

Specified by:
getStones in interface SingleGroup
Returns:
An array of Stone objects.

getTotalStones

public short getTotalStones()
Return the total number of stones in this group.

Specified by:
getTotalStones in interface SingleGroup
Returns:
A short which is the number of stones.

getLiberties

public Point[] getLiberties()
Get the points which are the liberties of this group.

Specified by:
getLiberties in interface SingleGroup
Returns:
An array of Point objects.

getTotalLiberties

public short getTotalLiberties()
Get the total number of liberties for this group.

Specified by:
getTotalLiberties in interface SingleGroup
Returns:
A short which is the number of liberties.

getAdjacentOpponentStones

public Stone[] getAdjacentOpponentStones()
Get all of the opponents stones adjacent to this group.

Specified by:
getAdjacentOpponentStones in interface SingleGroup
Returns:
An array of Stone objects.

getColor

public Color getColor()
Get the color of this group.

Specified by:
getColor in interface SingleGroup
Returns:
A Color object.

recompute

public void recompute(Board board)
Recompute the liberties and opponents for this group.

Specified by:
recompute in interface SingleGroup
Parameters:
board - The Board object.

getMinX

public int getMinX()
Return the smallest horizontal coordinate.

Specified by:
getMinX in interface SingleGroup
Returns:
An int which is the smallest horizontal coordinate.

getMaxX

public int getMaxX()
Return the largest horizontal coordinate.

Specified by:
getMaxX in interface SingleGroup
Returns:
An int which is the largest horizontal coordinate.

getMinY

public int getMinY()
Return the smallest vertical coordinate.

Specified by:
getMinY in interface SingleGroup
Returns:
An int which is the smallest vertical coordinate.

getMaxY

public int getMaxY()
Return the largest vertical coordinate.

Specified by:
getMaxY in interface SingleGroup
Returns:
An int which is the largest vertical coordinate.

toString

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

Overrides:
toString in class Object
Returns:
A String, which represents this object.

clone

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

Specified by:
clone in interface SingleGroup
Overrides:
clone in class Object
Returns:
A SingleGroupImpl object which is a clone of this one.