diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index 6369987..a7d01fe 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -252,17 +252,10 @@ public class Board { isAPieceHere = move.isRookMoveValid(x, y, color, selectX, selectY); } else if (type == PieceType.Queen) { - isAPieceHere = (move.isBishopMoveValid(x, y, color, selectX, selectY) || move.isRookMoveValid(x, y, color, selectX, selectY)); + isAPieceHere = (move.isBishopMoveValid(x, y, color, selectX, selectY) || move.isRookMoveValid(x, y, color, selectX, selectY)); // a queen is a Bishop and a rook, the move of both with an "Or" does the job ! } else if (type == PieceType.Knight) { - - if(selectX == x+1 && selectY == y+2 || selectX == x-1 && selectY == y-2 || - selectX == x-1 && selectY == y+2 || selectX == x+1 && selectY == y-2 || - selectX == x+2 && selectY == y+1 || selectX == x-2 && selectY == y-1 || - selectX == x-2 && selectY == y+1 || selectX == x+2 && selectY == y-1 ) { - isAPieceHere = true; - - } + isAPieceHere = move.isKnightMoveValid(x, y, color, selectX, selectY); } else if (type == PieceType.King){ for(int i = 1; i < 2;i++) { diff --git a/OOP_3B5_Project/src/backend/Move.java b/OOP_3B5_Project/src/backend/Move.java index e42ed9e..bc930f0 100644 --- a/OOP_3B5_Project/src/backend/Move.java +++ b/OOP_3B5_Project/src/backend/Move.java @@ -224,4 +224,49 @@ public class Move { return false; } + + public boolean isKnightMoveValid(int x, int y, boolean color, int selectX, int selectY) { + + if (selectX == x + 1 && selectY == y + 2) { + return true; + } + + + if (selectX == x - 1 && selectY == y - 2) { + return true; + } + + + if (selectX == x - 1 && selectY == y + 2) { + return true; + } + + + if (selectX == x + 1 && selectY == y - 2) { + return true; + } + + + if (selectX == x + 2 && selectY == y + 1) { + return true; + } + + + if (selectX == x - 2 && selectY == y - 1) { + return true; + } + + + if (selectX == x - 2 && selectY == y + 1) { + return true; + } + + + if (selectX == x + 2 && selectY == y - 1) { + return true; + } + + return false; + } + } \ No newline at end of file