still buggy but now state comes back to normal at turn 0

This commit is contained in:
hugomanipoud2 2025-05-23 11:49:01 +02:00
parent dada9a54cf
commit 48a3f7468d
1 changed files with 13 additions and 6 deletions

View File

@ -86,7 +86,7 @@ public class Board {
pieces.add(new Piece(i, 6, PieceType.Pawn, true));
}
saveBoardState(); // to save first state of the board
}
public void cleanBoard() {
@ -269,13 +269,20 @@ public class Board {
}
public void undoLastMove() {
if (turnNb > 0) { // only if turnnb is positive
turnNb--; // decrease turnNb
ArrayList<Piece> previousState = boardHistory.get(turnNb);// create a temporary arraylist
if (turnNb > 1) { // only if turnnb is positive
ArrayList<Piece> previousState = boardHistory.get(turnNb - 1);// create a temporary arraylist
pieces.clear(); // removes all pieces from arraylist of pieces used
pieces.addAll(previousState); // add all pieces from previous state of board to arraylist
boardHistory.remove(turnNb + 1); // removes the last state of board from memory
boardHistory.remove(turnNb);
turnNb--;
}else if (turnNb == 1) {
turnNb--;
pieces.clear();
boardHistory.clear();
populateBoard();
}
}