Fixed undoMove feature in ChessEngine

PGN
Justin 2025-06-22 01:58:47 +02:00
parent 7e4ac22e51
commit 3bad46f9ea
1 changed files with 7 additions and 1 deletions

View File

@ -23,7 +23,13 @@ public class ChessEngine {
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
if (board.legalMoves().contains(libMove)) {
board.doMove(libMove);
moves.add(libMove); // <-- hier merken!
//Replay? Dann abschneiden
if (currentMoveIndex < moves.size()) {
moves = new ArrayList<>(moves.subList(0, currentMoveIndex));
}
moves.add(libMove);
currentMoveIndex++;
return true;
}
return false;