mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Ändra från stream
This commit is contained in:
parent
dd96c3e56c
commit
0adba36150
@ -174,38 +174,22 @@ public abstract class Piece {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean checkIfSchack(Point pos, Piece[][] pieces) {
|
boolean checkIfSchack(Point pos, Piece[][] pieces) {
|
||||||
boolean ourColor = this.isWhite();
|
|
||||||
Piece selectedPiece = this;
|
Piece selectedPiece = this;
|
||||||
ArrayList<Point> attacks = new ArrayList<>();
|
ArrayList<Point> attacks = new ArrayList<>();
|
||||||
|
|
||||||
// Fråga alla pjäser vart de kan gå/ta
|
// Fråga alla pjäser vart de kan gå/ta
|
||||||
Arrays.stream(pieces).forEach(array -> {
|
for (Piece[] pieceArr : pieces) {
|
||||||
Arrays.stream(array).filter(piece -> piece != null && piece.isWhite() != this.isWhite()).forEach(piece -> {
|
|
||||||
attacks.addAll(piece.validAttacks(pieces));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/* for (Piece[] pieceArr : pieces) {
|
|
||||||
for (Piece piece : pieceArr) {
|
for (Piece piece : pieceArr) {
|
||||||
// Ifall det är tomrum skippa
|
if (piece != null && piece.isWhite() != this.isWhite()) {
|
||||||
if (piece == null) {
|
attacks.addAll(piece.validAttacks(pieces));
|
||||||
continue;
|
|
||||||
} else if (piece.isWhite() == ourColor) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lägg till alla attacker för mostståndaren
|
|
||||||
attacks.addAll(piece.validAttacks(pieces));
|
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
// Kollar ifall kungen står i schack just nu
|
// Kollar ifall kungen står i schack just nu
|
||||||
for (Point attack : attacks) {
|
for (Point attack : attacks) {
|
||||||
Piece attacked = pieces[attack.x][attack.y];
|
Piece attacked = pieces[attack.x][attack.y];
|
||||||
if (attacked == null) {
|
if (attacked != null && attacked.supremeRuler) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (attacked.supremeRuler) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user