From 58f038d0f2fe49f7941308fa56fe27fbaa36662d Mon Sep 17 00:00:00 2001 From: manon Date: Tue, 20 May 2025 11:08:08 +0200 Subject: [PATCH] Autoplayer implemented (needs to modify speed and checkmate condition) --- src/backend/Board.java | 7 +++++-- src/backend/Game.java | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 3fce592..ffff2fe 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -381,8 +381,11 @@ public class Board { } public void playMove(Move move) { - if (move == null) return; - + if (move == null || move.getPiece() == null) { + System.out.println("Invalid move: " + move); + return; + } + Piece piece = move.getPiece(); int toX = move.getToX(); int toY = move.getToY(); diff --git a/src/backend/Game.java b/src/backend/Game.java index 5673f34..7a29fae 100644 --- a/src/backend/Game.java +++ b/src/backend/Game.java @@ -52,9 +52,10 @@ public class Game extends Thread { } private void aiPlayerTurn() { - if(isAITurn()) { - board.playMove(aiPlayer.computeBestMove(new Board(board))); - } + if (isAITurn()) { + Move move = aiPlayer.computeBestMove(board); // Use the actual board + board.playMove(move); // Move from the actual board + } } public void clickCoords(int x, int y) {