still buggy but now state comes back to normal at turn 0
This commit is contained in:
parent
dada9a54cf
commit
48a3f7468d
|
|
@ -86,7 +86,7 @@ public class Board {
|
||||||
pieces.add(new Piece(i, 6, PieceType.Pawn, true));
|
pieces.add(new Piece(i, 6, PieceType.Pawn, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBoardState(); // to save first state of the board
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
|
|
@ -269,14 +269,21 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
if (turnNb > 0) { // only if turnnb is positive
|
if (turnNb > 1) { // only if turnnb is positive
|
||||||
turnNb--; // decrease turnNb
|
|
||||||
ArrayList<Piece> previousState = boardHistory.get(turnNb);// create a temporary arraylist
|
ArrayList<Piece> previousState = boardHistory.get(turnNb - 1);// create a temporary arraylist
|
||||||
|
|
||||||
pieces.clear(); // removes all pieces from arraylist of pieces used
|
pieces.clear(); // removes all pieces from arraylist of pieces used
|
||||||
pieces.addAll(previousState); // add all pieces from previous state of board to arraylist
|
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) {
|
public Board(Board board) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue