hightlightKinginCheck changes
Change-Id: I7ffb96e6d228a72a198559cc649367b97b968675
This commit is contained in:
commit
c084635905
|
|
@ -500,25 +500,41 @@ public class Board implements Cloneable {
|
|||
}
|
||||
|
||||
public void highlightKingInCheck() {
|
||||
|
||||
boolean isWhiteTurn = isTurnWhite();
|
||||
|
||||
// Determine the color of the current player
|
||||
boolean isWhiteTurn = isTurnWhite();
|
||||
|
||||
// Find the current player's king piece
|
||||
Piece king = null;
|
||||
boolean isTurnWhite = isTurnWhite();
|
||||
|
||||
Piece king = null;
|
||||
for (Piece piece : pieces) {
|
||||
if (piece.getType() == PieceType.King && piece.isWhite() == isWhiteTurn) {
|
||||
king = piece;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Piece piece : pieces) {
|
||||
if (piece.getType() == PieceType.King && piece.isWhite() == isWhiteTurn) {
|
||||
king = piece;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (king == null) {
|
||||
throw new IllegalStateException("No king found for the current player!");
|
||||
}
|
||||
|
||||
// Get all legal moves of the opponent's pieces
|
||||
ArrayList<Move> opponentMoves = getAllLegalMoves(!isWhiteTurn);
|
||||
|
||||
ArrayList<Move> opponentMoves = getAllLegalMoves(!isWhiteTurn);
|
||||
|
||||
|
||||
for (Move move : opponentMoves) {
|
||||
if (move.getToCol() == king.getX() && move.getToRow() == king.getY()) {
|
||||
highlightedPositions.add(new int[]{king.getX(), king.getY()});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any opponent move targets the king's position
|
||||
for (Move move : opponentMoves) {
|
||||
if (move.getToCol() == king.getX() && move.getToRow() == king.getY()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue