auto player update

This commit is contained in:
MSI-AB\antoineB 2025-05-23 09:12:36 +02:00
parent b3006d9708
commit 03175f9e5b
2 changed files with 6 additions and 8 deletions

View File

@ -4,13 +4,13 @@ import java.util.ArrayList;
public class AutoPlayer {
private static final int MAX_DEPTH = 2; // You can increase this for stronger AI
private final int MAX_DEPTH = 2; // Now an instance variable
public Move computeBestMove(Board board) {
return minimax(board, MAX_DEPTH, board.isTurnWhite()).bestMove;
}
private static class ScoredMove {
private class ScoredMove {
Move bestMove;
int score;
@ -20,7 +20,7 @@ public class AutoPlayer {
}
}
private ScoredMove minimax(Board board, int depth, boolean isMaximizing) {
public ScoredMove minimax(Board board, int depth, boolean isMaximizing) {
if (depth == 0) {
return new ScoredMove(null, evaluateBoard(board));
}
@ -66,7 +66,7 @@ public class AutoPlayer {
for (Piece piece : board.getPieces()) {
if (piece.isWhite() != isWhite) continue;
ArrayList<int[]> legalMoves = board.computeLegalMovesSafe(piece);
ArrayList<int[]> legalMoves = board.computeLegalMoves(piece);
for (int[] move : legalMoves) {
Piece target = getPieceAt(board, move[0], move[1]);
Move candidate = new Move(
@ -94,11 +94,9 @@ public class AutoPlayer {
}
}
private Piece getPieceAt(Board board, int x, int y) {
for (Piece p : board.getPieces()) {
if (p.getX() == x && p.getY() == y) return p;
}
return null;
}
return null;}
}

View File

@ -47,5 +47,5 @@ public class GameSoundManager {
if (jblClip != null) jblClip.stop();
if (backgroundClip != null) backgroundClip.stop();
}
}
}