if(style12.isMyGame()) {
gameNumber = style12.getGameNumber();
opponent = style12.getOpponentName();
if(style12.isInitialPosition()) {
currentBoard = new BitBoard().initialise();
}
}
if ( ! (style12.getMyRelationToGame() == Style12.REL_ME_TO_MOVE)) {
return;
}
if(style12.isFlagged()) {
gameNumber = -1;
currentBoard = null;
return;
}
if(style12.getHalfMoveCount() >= 100) {
log.info("Claiming draw by 50-move rule");
send("draw");
return;
}
if(currentBoard != null && !"none".equals(style12.getPreviousMovePGN())) {
try {
PGNUtils.applyMove(currentBoard, style12.getPreviousMovePGN());
} catch (Exception x) {
log.log(Level.SEVERE, "Apply move failed", x);
}
}
if(currentBoard == null || ! currentBoard.getCacheId().equals(style12.getBoard().getCacheId())) {
log.warning("Out of sync board detected - resetting!");
currentBoard = style12.getBoard();
}
if(currentBoard.getRepeatedCount() >= 3) {
log.info("Claiming draw by 3-fold repitition (opp move)");
send("draw");
return;
}
String bookMove = openingBook.getBookMove(currentBoard);
if(bookMove != null) {
PGNUtils.applyMove(currentBoard, bookMove);
send(bookMove);
log.fine("Using book move: " + bookMove);
return;
}
Runnable moveMaker = new Runnable() {
public void run() {
BitBoard myBoard = currentBoard;
ChessEngine searchNode = new ChessEngine();
String bestMove = searchNode.getPreferredMove(myBoard);
if(bestMove != null) {
if(gameNumber != -1) {
log.info("Moving: " + PGNUtils.translateMove(myBoard, bestMove));