/**
* Title: Pancet<p>
*
* Description: This is part of Pancet, a game applet. It
* encapsulates a single move within the move tree stored in the
* move library. This includes linkage values and the value
* flipped, which represents it's value to the move tree.<p>
*
* Copyright: Bongo Technologies (c) 2005<p>
*
* @author Mark Bondurant
* @version 3.0
*/
class Move implements GameConstants {
private boolean flipped = false;
private int[] parent = new int[4];
private int move;
/**
* This converts play area configurations into key values
* that can be used to index into the move library.
*/
static String key(int[] b) {
String k = String.valueOf(b[BOWL_A] * 1000 + b[BOWL_B] * 100 +
b[BOWL_C] * 10 + b[BOWL_D]);
while (k.length() < 4) k = "0" + k;
return k;
}
/**
* This creates a new, untried move object.
*/
Move(int[] b, int mv) {
for (int i=0; i<4; i++) parent[i] = b[i];
move = mv;
}
/**
* This creates a new tried move object. This is one that will
* be discarded at the first sign of failure. Moves of this sort
* are usually forced moves where this only a single option to
* choose from.
*/
Move(int[] b, int mv, boolean f) {
for (int i=0; i<4; i++) parent[i] = b[i];
move = mv;
flipped = f;
}
/**
* This is left in because it has proven useful in debugging.
*/
public String toString() {
return "parent=" + this.parent_key()
+ " move=" + this.move() + " flipped=" + this.flipped();
}
String parent_key() {
return key(parent);
}
boolean flipped() {
return flipped;
}
int move() {
return move;
}
void move(int m) {
move = m;
}
/**
* Most moves have two possibilities. Once one has been proven
* to fail, the move object is flipped to force the second possibility
* to be tried.
*/
void flip() {
move = (move == BOWL_A) ? BOWL_B : BOWL_A;
flipped = true;
}
}