This is a draft spec for a program which will be able to recommend moves in "SameGame" (PS2 from the OOP course). David has suggested that I distribute this as a Java Bean. We'll see. Suggestions for improvements to the spec are welcome. I have put comments on anything that I thought wasn't self-evident. Let me know if more comments are necessary.
/**
public interface Board {
An instance of this class is able to find the "best" move in a given
SameGame position.
*/
public class SamePlayer { /* Find the value of a given
position.
Value is defined as the number of additional points that an
evaluator expects can be scored from the position, including
the clearing bonus.*/
public int evaluate (Board b);
public Cell findBest (Board b); // Find the best move.
public void setEvaluator (Evaluator e); /* If you want to use
your own position evaluator and the standard logic, call this.*/
public void setEvaluatorParms (Object o); /* This object is
passed unchanged to the evaluator. It can contain parameters (e.g.,
number of points to subtract for clusters of singlet cells)
that the evaluator needs.*/
public void setMaxPositions (int n); /* The approximate
number of positions that you want to have evaluated in order to determine
the best move. The default is 200.*/
public void setCacheSize (int n); /* A cache of evaluated
positions will be maintained to save time. By default, this is the same as the
previous value and will vary with it if no specific limit is set by
calling this function.*/
}
// Usually 1000
public int getCellColor (Cell p);
public static final int EMPTY, RED,
GREEN, BLUE;
public int getWidth ();
public int getHeight ();
public int getClearScore ();
}
/**
public class Cell {
An object which implements this interface will be able to take a board
position and estimate the number of points that can be scored.
*/
public interface Evaluator {
public int evaluate (Board b, Object o);
}
public Point (int r, int c);
public int getRow ();
public int getColumn ();
}