Fixed FEN string export when board is in start position

This commit is contained in:
Kai S. K. Engelbart 2019-07-24 15:58:23 +02:00
parent dec0dc08ad
commit 686b76ed8a
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
2 changed files with 5 additions and 3 deletions

View File

@ -461,11 +461,13 @@ public class Board implements Cloneable {
// TODO: en passant availability // TODO: en passant availability
sb.append(" -"); sb.append(" -");
final LoggedMove lastMove = log.getLast();
// Halfmove clock // Halfmove clock
sb.append(" " + log.getLast().halfmoveClock); sb.append(" " + String.valueOf(lastMove == null ? 0 : lastMove.halfmoveClock));
// Fullmove counter // Fullmove counter
sb.append(" " + log.getLast().fullmoveCounter); sb.append(" " + String.valueOf(lastMove == null ? 1 : lastMove.fullmoveCounter));
return sb.toString(); return sb.toString();
} }

View File

@ -35,7 +35,7 @@ public class Log implements Cloneable {
moves.add(new LoggedMove(move, capturedPiece, fullmoveCounter, halfmoveClock)); 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() { public void removeLast() {
if (!moves.isEmpty()) { if (!moves.isEmpty()) {