added all possibilities and it was weird but after reseting the K

variable it works ! now i need to add condition for opposite color
peices to be eaten
This commit is contained in:
hugomanipoud2 2025-05-21 13:11:23 +02:00
parent 4a42f94ce8
commit 5e3c50adc8
1 changed files with 29 additions and 9 deletions

View File

@ -239,7 +239,7 @@ 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 < 8;i++) {
for(int i = 1; i < k;i++) {
if (getPiece(selectX + i, selectY + i) != null) {
k = i;
break;
@ -247,15 +247,35 @@ public class Board {
if (selectX + i == x && selectY + i == y) {
isAPieceHere = true;
}
}
} k = 8;
for (int i = 1; i < k; i++) {
// the sign || is an "or" condition, its needed to fullfill all the case possible, if not we are just heading to one direction
if(selectX == x-i && selectY == y-i ||
selectX == x-i && selectY == y+i || selectX == x+i && selectY == y-i) {
isAPieceHere = true;
}
}
if (getPiece(selectX - i, selectY - i) != null) {
k = i;
break;
}
if (selectX - i == x && selectY - i == y) {
isAPieceHere = true;
}
} k = 8;
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;
}
} k = 8;
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;
}
}
} else if (type == PieceType.Rook) {
for(int i = 1; i < 8;i++) {