Fixed Game and Log synchronization on FEN loading

This commit is contained in:
Kai S. K. Engelbart 2019-08-13 05:59:47 +02:00
parent ae6c618b40
commit b72a8916a0
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
2 changed files with 7 additions and 13 deletions

View File

@ -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));
}

View File

@ -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);