From 2a24efa355b992a50fef14f03bcdaf285218ad57 Mon Sep 17 00:00:00 2001 From: clara Date: Mon, 19 May 2025 18:36:18 +0200 Subject: [PATCH] Undo last move works !!!!!implementation of the method getLastMove in userTouch + method modified to save the current state --- src/backend/Board.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 4258072..1a72fa7 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -187,6 +187,8 @@ public class Board { System.out.println("Invalid move — not in highlighted squares."); return; } + // store the current state before making a move + getLastMove(); //store for castling int originalX = selectedPiece.getX(); @@ -316,11 +318,10 @@ public class Board { return false; } - 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 - getLastMove(selectedX, selectedY); - } + //new method to save the current state of the board + public void getLastMove() { + previousStates.add(new Board(this)); // Create a copy of the current board state + } public void undoLastMove() {