mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Stream
This commit is contained in:
parent
2bd8388488
commit
dd96c3e56c
@ -6,6 +6,7 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
public abstract class Piece {
|
public abstract class Piece {
|
||||||
@ -178,7 +179,13 @@ public abstract class Piece {
|
|||||||
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
|
||||||
for (Piece[] pieceArr : pieces) {
|
Arrays.stream(pieces).forEach(array -> {
|
||||||
|
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
|
// Ifall det är tomrum skippa
|
||||||
if (piece == null) {
|
if (piece == null) {
|
||||||
@ -190,8 +197,8 @@ public abstract class Piece {
|
|||||||
// Lägg till alla attacker för mostståndaren
|
// Lägg till alla attacker för mostståndaren
|
||||||
attacks.addAll(piece.validAttacks(pieces));
|
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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user