Fixed Game and Log synchronization on FEN loading
This commit is contained in:
parent
ae6c618b40
commit
b72a8916a0
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user