From 0a8f9c79967b43fe8ba6b3a0017a82dbefdc1929 Mon Sep 17 00:00:00 2001 From: loveb Date: Thu, 24 Mar 2022 09:31:29 +0100 Subject: [PATCH] Start --- src/schack/King.java | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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<>();