From ae6c618b407bd28a8d96dbf345b3e933da8c82ea Mon Sep 17 00:00:00 2001 From: kske Date: Tue, 13 Aug 2019 05:43:26 +0200 Subject: [PATCH] Implemented loadFromFen method in Board --- src/dev/kske/chess/board/Board.java | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/dev/kske/chess/board/Board.java b/src/dev/kske/chess/board/Board.java index 184140b..bdd4f0d 100644 --- a/src/dev/kske/chess/board/Board.java +++ b/src/dev/kske/chess/board/Board.java @@ -400,8 +400,7 @@ public class Board implements Cloneable { for (int l = j; l < Character.digit(places[k], 10); l++, j++) boardArr[j][i] = null; --j; - } - else { + } else { Color color = Character.isUpperCase(places[k]) ? Color.WHITE : Color.BLACK; switch (Character.toLowerCase(places[k])) { case 'k': @@ -435,7 +434,34 @@ public class Board implements Cloneable { // Active color log.setActiveColor(Color.fromFirstChar(parts[1].charAt(0))); - // TODO: other fields, synchronize with log and game + // Castling rights + for (char c : parts[2].toCharArray()) + switch (c) { + case 'K': + castlingRights.get(Color.WHITE).put(Type.KING, true); + case 'Q': + castlingRights.get(Color.WHITE).put(Type.QUEEN, true); + case 'k': + castlingRights.get(Color.BLACK).put(Type.KING, true); + case 'q': + castlingRights.get(Color.BLACK).put(Type.QUEEN, true); + case '-': + break; + default: + System.err + .printf("Unknown character '%c' in castling rights declaration of FEN string '%s'", c, fen); + } + + // En passant availability + if (!parts[3].equals("-")) log.setEnPassant(Position.fromSAN(parts[3])); + + // Halfmove clock + log.setHalfmoveClock(Integer.parseInt(parts[4])); + + // Fullmove counter + log.setFullmoveCounter(Integer.parseInt(parts[5])); + + // TODO: Synchronize with game } /**