This commit is contained in:
loveb 2022-03-24 09:31:29 +01:00
parent 4f4a4e2293
commit 0a8f9c7996

View File

@ -7,7 +7,6 @@ import java.util.LinkedHashSet;
public final class King extends PieceKnownIfMoved {
public King(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition);
setPieceIcon("King");
@ -22,6 +21,36 @@ public final class King extends PieceKnownIfMoved {
return true;
}
private void addCastlingIfCan(Piece[][] pieces, LinkedHashSet<Point> movable, Point toMove, Point selected) {
if (hasMoved) {
return;
}
// Vänster
for (int kingX = this.position.x - 1; kingX >= 0; kingX--) {
if (kingX == 0) {
try {
} catch (Exception e) {
}
}
boolean shouldBreak = addMovesIfCan(new Point(kingX, this.position.y), movable, pieces);
if (shouldBreak) {
break;
}
}
// Höger
for (int kingX = this.position.x + 1; kingX <= 7; kingX++) {
boolean shouldBreak = addMovesIfCan(new Point(kingX, this.position.y), movable, pieces);
if (shouldBreak) {
break;
}
}
}
@Override
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
LinkedHashSet<Point> movable = new LinkedHashSet<>();