From 8dc6c67272d59736f8d4d1cad1a958fe059f4072 Mon Sep 17 00:00:00 2001 From: hugomanipoud2 Date: Wed, 21 May 2025 14:40:16 +0200 Subject: [PATCH] added docstring to explain the ishighlighted method --- OOP_3B5_Project/src/backend/Board.java | 31 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index a8cb6f2..737d717 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -239,15 +239,28 @@ public class Board { } } else if (type == PieceType.Bishop) { int k = 8; // default range value for bishop to cover the board wherever he is - for(int i = 1; i < k;i++) { - if (getPiece(selectX + i, selectY + i) != null) { - k = i; - break; - } - if (selectX + i == x && selectY + i == y) { - isAPieceHere = true; + for(int i = 1; i < k; i++) { // range from 1 to k up until the follwing if statement is true + if (getPiece(selectX + i, selectY + i) != null) { // true Iff there is a piece at the specified position which are the direction of the specified piece ! + if (color != getPiece(selectX + i, selectY + i).isWhite()) { // another condition that will be lauched IFF the case has a piece in it and IFF the piece is of a != color than the played piece + k = i+1; // if color is diffrent, change K to i (number of case before a piece) + 1 (if the piece is of a different color i can eat it) + + if (selectX + i == x && selectY + i == y) { // iterates trough i but k = i+1 so the for loop will itterate until i+1 allowing for the opposite color piece to be eaten + isAPieceHere = true; //set the boolean var to true + } + break; // break the loop + + } else { + k = i; // if the condition "if (color != getPiece(selectX + i, selectY + i).isWhite())" is not compliant, this else statement will change k to be i, hence, the same colored piece present in its path will not be eaten + break; + } } - } k = 8; + if(selectX + i == x && selectY + i == y) { // iterate trough i up until i as k = i, it is needed to not light up the pieces of the same color a the played piece + isAPieceHere = true;//set the boolean var to true + } + + + + } k = 8; for (int i = 1; i < k; i++) { if (getPiece(selectX - i, selectY - i) != null) { k = i; @@ -266,7 +279,7 @@ public class Board { isAPieceHere = true; } - } k = 8; + } k = 8; for (int i = 1; i < k; i++) { if (getPiece(selectX + i, selectY - i) != null) { if (color != getPiece(selectX + i, selectY - i).isWhite()) {