From 4b99d6e233c8996e688388022085761b048428c7 Mon Sep 17 00:00:00 2001 From: valen Date: Sun, 22 Jun 2025 17:37:09 +0200 Subject: [PATCH] =?UTF-8?q?Quicksave=20programmiert=20(muss=20nur=20noch?= =?UTF-8?q?=20mit=20Buttons=20verkn=C3=BCpft=20werden)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Variable: private MoveBackup quicksave = null; hinzugefügt Methoden: save() und load() --- .../informatik/chess/model/ChessEngine.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/schach/src/main/java/de/hs_mannheim/informatik/chess/model/ChessEngine.java b/schach/src/main/java/de/hs_mannheim/informatik/chess/model/ChessEngine.java index 90be5aa..ee3b443 100644 --- a/schach/src/main/java/de/hs_mannheim/informatik/chess/model/ChessEngine.java +++ b/schach/src/main/java/de/hs_mannheim/informatik/chess/model/ChessEngine.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import com.github.bhlangonijr.chesslib.Board; +import com.github.bhlangonijr.chesslib.MoveBackup; import com.github.bhlangonijr.chesslib.Piece; import com.github.bhlangonijr.chesslib.Square; import com.github.bhlangonijr.chesslib.move.Move; @@ -10,7 +11,9 @@ import com.github.bhlangonijr.chesslib.move.Move; public class ChessEngine { private Board board; private List moves = new ArrayList<>(); + private MoveBackup quicksave = null; + public ChessEngine() { board = new Board(); } @@ -27,6 +30,25 @@ public class ChessEngine { return false; } + + public void save() { + if (!moves.isEmpty()) { + Move lastMove = moves.get(moves.size() - 1); + quicksave = new MoveBackup(board, lastMove); + System.out.println("Quicksave erstellt."); + } else { + System.out.println("Kein Zug vorhanden zum Speichern."); + } + } + + public void load() { + if (quicksave != null) { + quicksave.restore(board); + } + } + + + public List getLegalDestinations(String from) { List destinations = new ArrayList<>(); Square fromSq = Square.valueOf(from.toUpperCase());