org.moyoman.util
Class MoveDescriptorForest

java.lang.Object
  |
  +--org.moyoman.util.MoveDescriptorForest
All Implemented Interfaces:
Cloneable, Serializable

public class MoveDescriptorForest
extends Object
implements Serializable, Cloneable

This class is used to represent a forest of MoveDescriptor objects. This would be used in describing sequences of moves. There is an initial set of moves that can be made. For each of those moves, there is some set of moves that can be made. Each of these moves is represented as MoveDescriptor object.
This class could be used for representing things like josekis, or sequences of moves in a life and death problem.
Each move in a sequence should be the opposite color from the previous move. By convention, if one side makes two moves in a row, for example if one side makes a move in the corner, the other side plays elsewhere and then the first side makes a second move, in between the two moves should be a move by the second side which is a pass. This can be used both to show that the two moves in a row is not a mistake, and also to indicate that a position is non-urgent and that the second side does not necessarily need to resopnd.

See Also:
Serialized Form

Field Summary
private  HashMap forest
          The key is a MoveDescriptor, and the value is a HashMap contains MoveDescriptor objects.
private  HashSet initial
          Each element is a MoveDescriptor, which is also a key in forest.
 
Constructor Summary
MoveDescriptorForest()
           
 
Method Summary
 void addInitialMoveDescriptor(MoveDescriptor md)
          Add an initial move to the list.
 void addInitialMoveDescriptors(MoveDescriptor[] md)
          Add initial moves to the list.
 void addMoveDescriptor(MoveDescriptor parent, MoveDescriptor subsequent)
          Add a follow up move to a move which was already added.
 void addMoveDescriptors(MoveDescriptor parent, MoveDescriptor[] subsequent)
          Add follow up moves to a move which was already added.
 void clear()
          Remove all entries.
 Object clone()
          Override the Object.clone() method.
private  void cloneTree(HashMap newHM, MoveDescriptor md, HashMap oldForest, HashMap oldNew)
           
 MoveDescriptor[] getInitialMoveDescriptors()
          Return the possible initial moves.
 MoveDescriptor[] getSubsequentMoveDescriptors(MoveDescriptor parent)
          Return all of the follow up moves for the specified move.
static void main(String[] args)
           
private  String moveString(Move move)
           
private  String nextString(MoveDescriptor md, int index)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

forest

private HashMap forest
The key is a MoveDescriptor, and the value is a HashMap contains MoveDescriptor objects.


initial

private HashSet initial
Each element is a MoveDescriptor, which is also a key in forest.

Constructor Detail

MoveDescriptorForest

public MoveDescriptorForest()
Method Detail

main

public static void main(String[] args)

getInitialMoveDescriptors

public MoveDescriptor[] getInitialMoveDescriptors()
Return the possible initial moves.

Returns:
An array of MoveDescriptor objects.

getSubsequentMoveDescriptors

public MoveDescriptor[] getSubsequentMoveDescriptors(MoveDescriptor parent)
                                              throws NoSuchDataException
Return all of the follow up moves for the specified move.

Parameters:
parent - - The move for which the follow up moves are being retrieved.
Returns:
An array of MoveDescriptor objects.
Throws:
NoSuchDataException - Thrown if the parent is not found.

addInitialMoveDescriptor

public void addInitialMoveDescriptor(MoveDescriptor md)
Add an initial move to the list.

Parameters:
md - - The initial move to be added.

addInitialMoveDescriptors

public void addInitialMoveDescriptors(MoveDescriptor[] md)
Add initial moves to the list.

Parameters:
md - - The initial moves to be added.

addMoveDescriptor

public void addMoveDescriptor(MoveDescriptor parent,
                              MoveDescriptor subsequent)
                       throws NoSuchDataException
Add a follow up move to a move which was already added.

Parameters:
parent - - The move which has already been added.
subsequent - - A follow up move to the parent.
Throws:
NoSuchDataException - Thrown if the parent is not found.

addMoveDescriptors

public void addMoveDescriptors(MoveDescriptor parent,
                               MoveDescriptor[] subsequent)
                        throws NoSuchDataException
Add follow up moves to a move which was already added.

Parameters:
parent - - The move which has already been added.
subsequent - - Follow up moves to the parent.
Throws:
NoSuchDataException - Thrown if the parent is not found.

clear

public void clear()
Remove all entries.


toString

public String toString()
Overrides:
toString in class Object

moveString

private String moveString(Move move)

nextString

private String nextString(MoveDescriptor md,
                          int index)

clone

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

Overrides:
clone in class Object
Returns:
A MoveDescriptorForest object which is a clone of this one.

cloneTree

private void cloneTree(HashMap newHM,
                       MoveDescriptor md,
                       HashMap oldForest,
                       HashMap oldNew)