Maybe last commit, i will try to allow castling with undolastmove

This commit is contained in:
hugomanipoud2 2025-05-23 12:40:43 +02:00
parent 9b5e116e42
commit a37a1a8d76
2 changed files with 4 additions and 7 deletions

View File

@ -275,21 +275,17 @@ public class Board {
public void undoLastMove() {
if (turnNb > 1) { // only if turnnb is positive
turnNb--;
ArrayList<Piece> previousState = boardHistory.get(turnNb);// create a temporary arraylist
ArrayList<Piece> previousState = boardHistory.get(turnNb);// 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);
printBoardHistory();
}else if (turnNb == 1) {
turnNb--;
pieces.clear();
boardHistory.clear();
populateBoard();
printBoardHistory();
}
}
@ -303,6 +299,8 @@ public class Board {
}
// used to debug undolastmove
public void printBoardHistory() {
System.out.println("Board History:");
for (Map.Entry<Integer, ArrayList<Piece>> entry : boardHistory.entrySet()) {

View File

@ -39,7 +39,6 @@ public class Move {
board.setTurnNb(turnNb + 1); // adds + 1 to turn nb
board.saveBoardState(); // after updating the pieces on the board and the turnNb, saves the current state of the board in a hashmap
System.out.println(board.toString()); // prints the current state of board
board.printBoardHistory();
}
break;
}