org.moyoman.module.loosegroups.simplelgimpl
Class SingleLGImpl

java.lang.Object
  |
  +--org.moyoman.module.loosegroups.simplelgimpl.SingleLGImpl
All Implemented Interfaces:
Cloneable, Serializable, SingleLooseGroup

public class SingleLGImpl
extends Object
implements SingleLooseGroup, Cloneable, Serializable

This class represents a single loose group. A loose group consists of one or more groups of stones of the same color which tend to act as a single unit. Two examples are the stones of a corner enclosure, or two adjacent stones on the third and fourth lines, and another stone on the third line three spaces away.

See Also:
Serialized Form

Field Summary
private  Point[] edgePoints
          Contains the associated edge points for this group.
private  HashSet singleGroup
          Contains the SingleGroup objects which make up the loose group.
 
Constructor Summary
protected SingleLGImpl(SingleGroup sg)
          Create the SingleLGImpl object.
 
Method Summary
protected  void addSingleGroup(SingleGroup sg)
          Add a single group to this loose group.
protected  void addSingleGroups(SingleGroup[] sgarr)
          Add single groups to this loose group.
 Object clone()
          Override the Object.clone() method.
 Stone getAnyStone()
          Return one of the stones from this group.
 Stone[] getClosestStones(Point pt)
          Return the stones which are closest to the given point.
 Color getColor()
          Get the color of the stones in this group.
private  short getDistance(Point pt1, Point pt2)
          Get the square of the distance between two points.
 short getDistanceToClosestStones(Point pt)
          Get the distance to the closest stone in the group.
 short getMaxX()
          Get the largest horizontal value of any of the stones in this loose group.
 short getMaxY()
          Get the largest vertical value of any of the stones in this loose group.
 short getMinX()
          Get the smallest horizontal value of any of the stones in this loose group.
 short getMinY()
          Get the smallest vertical value of any of the stones in this loose group.
 SingleGroup[] getSingleGroups()
          Return the single groups that comprise this loose group.
 Stone[] getStones()
          Get all of the stones in this loose group.
 short getTotalSingleGroups()
          Return the total number of single groups that comprise this loose group.
 short getTotalStones()
          Get the total number of stones in this group.
 boolean isInBoundingBox(Point pt)
          Determine if the point is in the bounding box of the loose group.
 boolean isInSingleLooseGroup(SingleGroup sg)
          Return whether the single group is in the single loose group.
 boolean isInSingleLooseGroup(Stone stone)
          Return whether the stone is in the single loose group.
protected  void removeSingleGroup(SingleGroup sg)
          Remove a SingleGroup from this loose group.
protected  void removeSingleGroup(Stone stone)
          Remove the single group which contains this stone.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleGroup

private HashSet singleGroup
Contains the SingleGroup objects which make up the loose group.


edgePoints

private Point[] edgePoints
Contains the associated edge points for this group.

Constructor Detail

SingleLGImpl

protected SingleLGImpl(SingleGroup sg)
Create the SingleLGImpl object.

Parameters:
sg - A SingleGroup object which makes up the loose group.
Method Detail

addSingleGroup

protected void addSingleGroup(SingleGroup sg)
Add a single group to this loose group.

Parameters:
sg - The SingleGroup object to be added to this loose group.

addSingleGroups

protected void addSingleGroups(SingleGroup[] sgarr)
Add single groups to this loose group.

Parameters:
sgarr - An array of SingleGroup objects to be added to this loose group.

removeSingleGroup

protected void removeSingleGroup(SingleGroup sg)
Remove a SingleGroup from this loose group. The method for doing this might seem overly complicated, but is necessary due to issues arising from cloning.

Parameters:
sg - The group to be removed.

removeSingleGroup

protected void removeSingleGroup(Stone stone)
Remove the single group which contains this stone.

Parameters:
stone - The stone which is in the single group to be removed.

isInSingleLooseGroup

public boolean isInSingleLooseGroup(Stone stone)
Return whether the stone is in the single loose group.

Specified by:
isInSingleLooseGroup in interface SingleLooseGroup
Parameters:
stone - The stone in question.
Returns:
true if the stone is in the loose group, or false.

isInSingleLooseGroup

public boolean isInSingleLooseGroup(SingleGroup sg)
Return whether the single group is in the single loose group.

Specified by:
isInSingleLooseGroup in interface SingleLooseGroup
Parameters:
sg - The single group in question.
Returns:
true if the single group is in the loose group, or false.

getColor

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

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

getSingleGroups

public SingleGroup[] getSingleGroups()
Return the single groups that comprise this loose group.

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

getAnyStone

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

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

getClosestStones

public Stone[] getClosestStones(Point pt)
Return the stones which are closest to the given point. In the case where more than one stone is equally close, all are returned. No consideration is given of what opponents stone might be in the way.

Specified by:
getClosestStones in interface SingleLooseGroup
Parameters:
pt - The point in question.
Returns:
An array of Stone objects.

getDistance

private short getDistance(Point pt1,
                          Point pt2)
Get the square of the distance between two points. Since this value is only used for comparision, there is no reason to take the square root.

Parameters:
pt1 - One of the points.
pt2 - The other point.
Returns:
A short which is the square of the distance.

getDistanceToClosestStones

public short getDistanceToClosestStones(Point pt)
Description copied from interface: SingleLooseGroup
Get the distance to the closest stone in the group. The distance is the square of the geometric distance, so if the closest stone is 4 horizontal and 3 vertical, then this method returns 25. Use the org.moyoman.util.Sqrt class to get the actual distance if needed.

Specified by:
getDistanceToClosestStones in interface SingleLooseGroup
Parameters:
pt - The point in question.
Returns:
A short which is the square of the distance.

getMinX

public short getMinX()
Get the smallest horizontal value of any of the stones in this loose group.

Specified by:
getMinX in interface SingleLooseGroup
Returns:
A short which is the minimum horizontal value.

getMaxX

public short getMaxX()
Get the largest horizontal value of any of the stones in this loose group.

Specified by:
getMaxX in interface SingleLooseGroup
Returns:
A short which is the maximum horizontal value.

getMinY

public short getMinY()
Get the smallest vertical value of any of the stones in this loose group.

Specified by:
getMinY in interface SingleLooseGroup
Returns:
A short which is the minimum horizontal value.

getMaxY

public short getMaxY()
Get the largest vertical value of any of the stones in this loose group.

Specified by:
getMaxY in interface SingleLooseGroup
Returns:
A short which is the maximum horizontal value.

isInBoundingBox

public boolean isInBoundingBox(Point pt)
Determine if the point is in the bounding box of the loose group.

Specified by:
isInBoundingBox in interface SingleLooseGroup
Parameters:
pt - The point in question.
Returns:
true if the point is in the bounding box, or false.

getStones

public Stone[] getStones()
Get all of the stones in this loose group.

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

getTotalStones

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

Returns:
A short which is the total number of stones.

getTotalSingleGroups

public short getTotalSingleGroups()
Return the total number of single groups that comprise this loose group.

Specified by:
getTotalSingleGroups in interface SingleLooseGroup
Returns:
The total number of single groups.

clone

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

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