Fixed Game and Log synchronization on FEN loading
This commit is contained in:
parent
3ea48ef21b
commit
642a0bf4d1
@ -45,19 +45,10 @@ public class Log implements Cloneable {
|
|||||||
* @param pawnMove {@code true} if the move was made by a pawn
|
* @param pawnMove {@code true} if the move was made by a pawn
|
||||||
*/
|
*/
|
||||||
public void add(Move move, Piece capturedPiece, boolean pawnMove) {
|
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;
|
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;
|
if (activeColor == Color.BLACK) ++fullmoveCounter;
|
||||||
halfmoveClock = capturedPiece != null || pawnMove ? 0 : getLast().halfmoveClock + 1;
|
if (pawnMove || capturedPiece != null) halfmoveClock = 0;
|
||||||
}
|
else++halfmoveClock;
|
||||||
activeColor = activeColor.opposite();
|
activeColor = activeColor.opposite();
|
||||||
moves.add(new LoggedMove(move, capturedPiece, enPassant, activeColor, fullmoveCounter, halfmoveClock));
|
moves.add(new LoggedMove(move, capturedPiece, enPassant, activeColor, fullmoveCounter, halfmoveClock));
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,10 @@ public class MenuBar extends JMenuBar {
|
|||||||
.getBoard()
|
.getBoard()
|
||||||
.initFromFEN(JOptionPane.showInputDialog("Enter a FEN string: "));
|
.initFromFEN(JOptionPane.showInputDialog("Enter a FEN string: "));
|
||||||
mainWindow.getBoardPane().getBoardComponent().repaint();
|
mainWindow.getBoardPane().getBoardComponent().repaint();
|
||||||
|
mainWindow.getGame()
|
||||||
|
.getPlayers()
|
||||||
|
.get(mainWindow.getGame().getBoard().getLog().getActiveColor())
|
||||||
|
.requestMove();
|
||||||
});
|
});
|
||||||
toolsMenu.add(loadFromFENMenuItem);
|
toolsMenu.add(loadFromFENMenuItem);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user