diff --git a/src/schack/King.java b/src/schack/King.java index 08a51b4..c7b943c 100644 --- a/src/schack/King.java +++ b/src/schack/King.java @@ -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 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 validMoves(Piece[][] pieces) { LinkedHashSet movable = new LinkedHashSet<>();