From 642a0bf4d1390fc81b81ad7a8a47dc8fbe02b887 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 13 Aug 2019 05:59:47 +0200 Subject: [PATCH] Fixed Game and Log synchronization on FEN loading --- src/dev/kske/chess/board/Log.java | 15 +++------------ src/dev/kske/chess/ui/MenuBar.java | 5 ++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/dev/kske/chess/board/Log.java b/src/dev/kske/chess/board/Log.java index 544ebbf..56d34dd 100644 --- a/src/dev/kske/chess/board/Log.java +++ b/src/dev/kske/chess/board/Log.java @@ -45,19 +45,10 @@ public class Log implements Cloneable { * @param pawnMove {@code true} if the move was made by a pawn */ public void add(Move move, Piece capturedPiece, boolean pawnMove) { - // En passant availability enPassant = pawnMove && move.yDist == 2 ? new Position(move.pos.x, move.pos.y + move.ySign) : null; - - // Fullmove counter and halfmove clock - int fullmoveCounter, halfmoveClock; - if (moves.isEmpty()) { - fullmoveCounter = 1; - halfmoveClock = 0; - } else { - fullmoveCounter = getLast().fullmoveCounter; - if (activeColor == Color.BLACK) ++fullmoveCounter; - halfmoveClock = capturedPiece != null || pawnMove ? 0 : getLast().halfmoveClock + 1; - } + if (activeColor == Color.BLACK) ++fullmoveCounter; + if (pawnMove || capturedPiece != null) halfmoveClock = 0; + else++halfmoveClock; activeColor = activeColor.opposite(); moves.add(new LoggedMove(move, capturedPiece, enPassant, activeColor, fullmoveCounter, halfmoveClock)); } diff --git a/src/dev/kske/chess/ui/MenuBar.java b/src/dev/kske/chess/ui/MenuBar.java index 812a86d..f2522ea 100644 --- a/src/dev/kske/chess/ui/MenuBar.java +++ b/src/dev/kske/chess/ui/MenuBar.java @@ -90,7 +90,10 @@ public class MenuBar extends JMenuBar { .getBoard() .initFromFEN(JOptionPane.showInputDialog("Enter a FEN string: ")); mainWindow.getBoardPane().getBoardComponent().repaint(); - + mainWindow.getGame() + .getPlayers() + .get(mainWindow.getGame().getBoard().getLog().getActiveColor()) + .requestMove(); }); toolsMenu.add(loadFromFENMenuItem);