From 601104485c4f4966d769eb80a952f1f8ddf3d959 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 24 Jul 2019 15:58:23 +0200 Subject: [PATCH] Fixed FEN string export when board is in start position --- src/dev/kske/chess/board/Board.java | 6 ++++-- src/dev/kske/chess/board/Log.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dev/kske/chess/board/Board.java b/src/dev/kske/chess/board/Board.java index da98313..f99b2c9 100644 --- a/src/dev/kske/chess/board/Board.java +++ b/src/dev/kske/chess/board/Board.java @@ -461,11 +461,13 @@ public class Board implements Cloneable { // TODO: en passant availability sb.append(" -"); + final LoggedMove lastMove = log.getLast(); + // Halfmove clock - sb.append(" " + log.getLast().halfmoveClock); + sb.append(" " + String.valueOf(lastMove == null ? 0 : lastMove.halfmoveClock)); // Fullmove counter - sb.append(" " + log.getLast().fullmoveCounter); + sb.append(" " + String.valueOf(lastMove == null ? 1 : lastMove.fullmoveCounter)); return sb.toString(); } diff --git a/src/dev/kske/chess/board/Log.java b/src/dev/kske/chess/board/Log.java index 3311cd6..22d8bf2 100644 --- a/src/dev/kske/chess/board/Log.java +++ b/src/dev/kske/chess/board/Log.java @@ -35,7 +35,7 @@ public class Log implements Cloneable { moves.add(new LoggedMove(move, capturedPiece, fullmoveCounter, halfmoveClock)); } - public LoggedMove getLast() { return moves.get(moves.size() - 1); } + public LoggedMove getLast() { return moves.isEmpty() ? null : moves.get(moves.size() - 1); } public void removeLast() { if (!moves.isEmpty()) {