From acb9e05e0736079d33811fa1ee704d9f000ce7d0 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 16 Mar 2023 12:36:46 -0700 Subject: [PATCH] Fix king control zone, disable checks preventing castling --- src/King.java | 8 ++++---- src/Piece.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/King.java b/src/King.java index 36e62b4..acce730 100644 --- a/src/King.java +++ b/src/King.java @@ -28,8 +28,8 @@ public class King extends Piece { rightRook instanceof Rook && !rightRook.moved && board.get(position.x + 1, position.y) == null && - board.get(position.x + 2, position.y) == null && - !isInCheck(board) + board.get(position.x + 2, position.y) == null // && + // !isInCheck(board) ) { // TODO: Does not take into account squares in castling path being threatened Move rightCastle = new Move(position, new BoardCoordinate(position.x + 2, position.y)); @@ -46,8 +46,8 @@ public class King extends Piece { !leftRook.moved && board.get(position.x - 1, position.y) == null && board.get(position.x - 2, position.y) == null && - board.get(position.x - 3, position.y) == null && - !isInCheck(board) + board.get(position.x - 3, position.y) == null // && + // !isInCheck(board) ) { // TODO: Does not take into account squares in castling path being threatened Move leftCastle = new Move(position, new BoardCoordinate(position.x - 2, position.y)); diff --git a/src/Piece.java b/src/Piece.java index c770688..57fdc6f 100644 --- a/src/Piece.java +++ b/src/Piece.java @@ -61,7 +61,7 @@ public abstract class Piece { outer: for (int y = 0; y < Board.BOARD_SIZE; y++) { for (int x = 0; x < Board.BOARD_SIZE; x++) { Piece piece = board.get(x, y); - if (piece == null || piece.black == black || piece instanceof King) continue; + if (piece == null || piece.black == black) continue; ArrayList legalMoves = piece.getLegalMoves(new BoardCoordinate(x, y), board, false); for (Move legalMove : legalMoves) { Piece pieceAtMove = board.get(legalMove.to);