From 6787c0eae25c42bb966408be9694521ae2198e3e Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Wed, 21 May 2025 19:21:57 +0200 Subject: [PATCH] it finnaly works, need to check board getPiece(x,y) instead of selectedXY because only 1 case is concerned, knight an king soon ok --- OOP_3B5_Project/src/backend/Move.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/OOP_3B5_Project/src/backend/Move.java b/OOP_3B5_Project/src/backend/Move.java index 2d0d6f0..50c8895 100644 --- a/OOP_3B5_Project/src/backend/Move.java +++ b/OOP_3B5_Project/src/backend/Move.java @@ -228,15 +228,11 @@ public class Move { public boolean isKnightMoveValid(int x, int y, boolean color, int selectX, int selectY) { - if (selectX == x + 1 && selectY == y + 2) { + if (selectX == x + 1 && selectY == y + 2) { // check one of the 8 possible cases - if(board.getPiece(selectX + 1, selectY + 2) != null) { - - if(color != board.getPiece(selectX+ 1, selectY + 2).isWhite()) { - return true; - } - - } + if(board.getPiece(x, y) != null) { // check at the exact tox and ToY coordinates if there is a piece + return color != board.getPiece(x, y).isWhite(); // no need for additional if statement compared to previous move methods, its a comparator in between the color of the played piece and the color of the piece at the destination, if different, it will return true (possibility to eat the piecebc ishighlighted will be true) , if the same it will return false + } return true; }