diff --git a/OOP_3B5_Project/src/backend/Board.java b/OOP_3B5_Project/src/backend/Board.java index f33704c..d21b43c 100644 --- a/OOP_3B5_Project/src/backend/Board.java +++ b/OOP_3B5_Project/src/backend/Board.java @@ -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,14 +269,21 @@ public class Board { } public void undoLastMove() { - if (turnNb > 0) { // only if turnnb is positive - turnNb--; // decrease turnNb - ArrayList previousState = boardHistory.get(turnNb);// create a temporary arraylist + if (turnNb > 1) { // only if turnnb is positive + + ArrayList 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(); + } } public Board(Board board) {