Fixed Game and Log synchronization on FEN loading
This commit is contained in:
parent
17f110e7f7
commit
dcef49c4eb
@ -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;
|
||||||
|
if (activeColor == Color.BLACK) ++fullmoveCounter;
|
||||||
// Fullmove counter and halfmove clock
|
if (pawnMove || capturedPiece != null) halfmoveClock = 0;
|
||||||
int fullmoveCounter, halfmoveClock;
|
else++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;
|
|
||||||
}
|
|
||||||
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