|
|
@ -25,6 +25,7 @@ public class Board {
|
|
|
|
King whiteKing;
|
|
|
|
King whiteKing;
|
|
|
|
final DrawingPanel panel;
|
|
|
|
final DrawingPanel panel;
|
|
|
|
final Graphics graphics;
|
|
|
|
final Graphics graphics;
|
|
|
|
|
|
|
|
public boolean aiThinking = false;
|
|
|
|
|
|
|
|
|
|
|
|
// The board is a two-dimensional array of nullable pieces
|
|
|
|
// The board is a two-dimensional array of nullable pieces
|
|
|
|
Piece[][] board;
|
|
|
|
Piece[][] board;
|
|
|
@ -170,6 +171,7 @@ public class Board {
|
|
|
|
setup();
|
|
|
|
setup();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aiThinking) return;
|
|
|
|
// Get board coordinate of mouse click
|
|
|
|
// Get board coordinate of mouse click
|
|
|
|
BoardCoordinate coordinate = new ScreenCoordinate(x, y).toBoard();
|
|
|
|
BoardCoordinate coordinate = new ScreenCoordinate(x, y).toBoard();
|
|
|
|
// If there's no piece there, return
|
|
|
|
// If there's no piece there, return
|
|
|
@ -199,12 +201,18 @@ public class Board {
|
|
|
|
move(legalMove);
|
|
|
|
move(legalMove);
|
|
|
|
setLastMovedPieceAsMoved();
|
|
|
|
setLastMovedPieceAsMoved();
|
|
|
|
checkForCheckmate();
|
|
|
|
checkForCheckmate();
|
|
|
|
|
|
|
|
// Clear dragging
|
|
|
|
|
|
|
|
dragging = null;
|
|
|
|
|
|
|
|
// Redraw without dragging
|
|
|
|
|
|
|
|
draw();
|
|
|
|
if (!isGameOver) {
|
|
|
|
if (!isGameOver) {
|
|
|
|
move(ChessAI.findBestMove(this));
|
|
|
|
try {
|
|
|
|
setLastMovedPieceAsMoved();
|
|
|
|
ChessAI.move(this);
|
|
|
|
checkForCheckmate();
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
System.out.println(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|