boolean doPlay() {
try {
if (!freePlay) {
// This code doesn't allow to play undocumented moves
//
SGFNodeIterator i = game.kifuLastMove().iterator();
if (i.next(true) == null)
return false;
// search for appropriate variant
SGFMove newMove = new SGFMove(cursorX, cursorY, game.colorToPlay);
SGFMove variantMove;
i.firstVariant(true);
do {
variantMove = i.current().getMoveProperty();
} while (!newMove.equals(variantMove) && i.nextVariant(true) != null);
if (!newMove.equals(variantMove))
return false;
}
game.play(cursorX, cursorY);
snd.playStoneSound(game.colorToPlay == Board.WHITE);
// show player's move
notifyGameUpdated();
if (!probStarted) {
if (probCurrent != null)
probCurrent.tried++;
probStarted = true;
statusScreen.setProblem(probCurrent, probEnum);
}
if (gobanCanvas.showMoveHints)
setCursorToNextGoodMove();
else {
hasRespondMove = false;
SGFNodeIterator i = game.kifuLastMove().iterator();
if (i.next(true) != null) {
// play randomized response move
i.firstVariant(true);
int nGoodVariants = 0;
int nBadVariants = 0;
do {
if ((i.current().bits & SGFNode.GOOD_MOVE) != 0)
nGoodVariants++;
else if ((i.current().bits & SGFNode.BAD_MOVE) != 0)
nBadVariants++;
} while (i.nextVariant(true) != null);
// play response if there is good/bad hint
if (nGoodVariants > 0 || nBadVariants > 0) {
int k;
int mask;
Random rand = new Random();
if (nGoodVariants > 0) {
k = rand.nextInt(nGoodVariants);
mask = SGFNode.GOOD_MOVE;
} else {
k = rand.nextInt(nBadVariants);
mask = SGFNode.BAD_MOVE;
}
// k = 0 is valid good variant number, so in while it's >= 0
do {
if ((i.current().bits & mask) != 0)
k--;
} while (k >= 0 && i.prevVariant(true) != null);
SGFMove variantMove = i.current().getMoveProperty();
game.play(variantMove.x, variantMove.y, variantMove.color);
snd.playStoneSound(game.colorToPlay == Board.WHITE);
// show response
notifyGameUpdated();
hasRespondMove = true;
}
}
}
if (!probFinished) {
SGFNodeIterator i = game.kifuLastMove().iterator();
boolean haveGoodMove = (i.current().bits & SGFNode.GOOD_MOVE) != 0;
probFinished = i.next(false) == null || !haveGoodMove;
if (probFinished) {
if (haveGoodMove) {
if (probCurrent != null)
probCurrent.solved++;
statusScreen.setProblem(probCurrent, probEnum);