This commit is contained in:
clara 2025-05-13 16:22:30 +02:00
parent 2036a3d034
commit 5461e96cd4
2 changed files with 19 additions and 1 deletions

View File

@ -265,12 +265,29 @@ public class Board {
public void getLastMove (int x, int y) {// it saves the current state before making a move public void getLastMove (int x, int y) {// it saves the current state before making a move
previousStates.add(new Board(this)); // Use the existing constructor to create a copy previousStates.add(new Board(this)); // Use the existing constructor to create a copy
getLastMove(selectedX, selectedY);
} }
public void undoLastMove() { public void undoLastMove() {
if (!previousStates.isEmpty()) {
Board previousState = previousStates.remove(previousStates.size() - 1); // Get the last state
this.colNum = previousState.colNum;
this.lineNum = previousState.lineNum;
this.turnNumber = previousState.turnNumber;
this.isWhiteTurn = previousState.isWhiteTurn;
this.pieces = new ArrayList<>(previousState.pieces); // Restore pieces
// Reset selected positions and highlighted squares
this.selectedX = previousState.selectedX;
this.selectedY = previousState.selectedY;
this.highlightedSquares = new ArrayList<>(previousState.highlightedSquares);
} else {
System.out.println("There are no moves to undo.");
}
}
}
public Board(Board board) { public Board(Board board) {
this.colNum = board.colNum; this.colNum = board.colNum;

View File

@ -107,6 +107,7 @@ public class Game extends Thread {
board.undoLastMove(); board.undoLastMove();
} }
public void toggleAI(boolean isWhite) { public void toggleAI(boolean isWhite) {
this.activationAIFlags[isWhite?1:0] = !this.activationAIFlags[isWhite?1:0]; this.activationAIFlags[isWhite?1:0] = !this.activationAIFlags[isWhite?1:0];
} }