From d37206f77c35d701a2a30a9f143e827672a0171a Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Thu, 22 May 2025 19:08:26 +0200 Subject: [PATCH] trying to setup shortcastling --- OOP_3B5_Project/src/backend/Board.java | 2 +- OOP_3B5_Project/src/backend/Move.java | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index 8d6c0ec..ed8c9c7 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -230,7 +230,7 @@ public class Board { isAPieceHere = move.isKnightMoveValid(x, y, color, selectX, selectY); } else if (type == PieceType.King){ - isAPieceHere = move.isKingMoveValid(x, y, color, selectX, selectY); + isAPieceHere = move.isKingMoveValid(x, y, color, selectX, selectY, myPiece); } return isAPieceHere; } diff --git a/OOP_3B5_Project/src/backend/Move.java b/OOP_3B5_Project/src/backend/Move.java index 5608386..6759443 100644 --- a/OOP_3B5_Project/src/backend/Move.java +++ b/OOP_3B5_Project/src/backend/Move.java @@ -324,7 +324,7 @@ public class Move { return false; } -public boolean isKingMoveValid(int x, int y, boolean color, int selectX, int selectY) { +public boolean isKingMoveValid(int x, int y, boolean color, int selectX, int selectY, Piece myPiece) { if (selectX == x + 1 && selectY == y + 1) { // check one of the 8 possible cases @@ -366,6 +366,12 @@ public boolean isKingMoveValid(int x, int y, boolean color, int selectX, int se if (selectX == x + 1 && selectY == y) { return checkColor(x, y, color); } + if (color == true) { + if ((selectX == x - 3 && selectY == y)) { + return specialMoves.shortCastle(myPiece); + + } + } return false; } @@ -376,11 +382,13 @@ public boolean isKingMoveValid(int x, int y, boolean color, int selectX, int se return color != board.getPiece(x, y).isWhite(); // no need for additional if statement compared to rook and bishop move methods, its a comparator in between the color of the played piece and the color of the piece at the destination (x,y) , if they are different (so if the comparison is true), it will return true (possibility to eat the piece bc ishighlighted will be true) , if of the same color, return false } return true; - - - - - - -} + } + + + + + + + + } \ No newline at end of file