auto player update
This commit is contained in:
parent
b3006d9708
commit
03175f9e5b
|
|
@ -4,13 +4,13 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class AutoPlayer {
|
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) {
|
public Move computeBestMove(Board board) {
|
||||||
return minimax(board, MAX_DEPTH, board.isTurnWhite()).bestMove;
|
return minimax(board, MAX_DEPTH, board.isTurnWhite()).bestMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ScoredMove {
|
private class ScoredMove {
|
||||||
Move bestMove;
|
Move bestMove;
|
||||||
int score;
|
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) {
|
if (depth == 0) {
|
||||||
return new ScoredMove(null, evaluateBoard(board));
|
return new ScoredMove(null, evaluateBoard(board));
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ public class AutoPlayer {
|
||||||
for (Piece piece : board.getPieces()) {
|
for (Piece piece : board.getPieces()) {
|
||||||
if (piece.isWhite() != isWhite) continue;
|
if (piece.isWhite() != isWhite) continue;
|
||||||
|
|
||||||
ArrayList<int[]> legalMoves = board.computeLegalMovesSafe(piece);
|
ArrayList<int[]> legalMoves = board.computeLegalMoves(piece);
|
||||||
for (int[] move : legalMoves) {
|
for (int[] move : legalMoves) {
|
||||||
Piece target = getPieceAt(board, move[0], move[1]);
|
Piece target = getPieceAt(board, move[0], move[1]);
|
||||||
Move candidate = new Move(
|
Move candidate = new Move(
|
||||||
|
|
@ -94,11 +94,9 @@ public class AutoPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Piece getPieceAt(Board board, int x, int y) {
|
private Piece getPieceAt(Board board, int x, int y) {
|
||||||
for (Piece p : board.getPieces()) {
|
for (Piece p : board.getPieces()) {
|
||||||
if (p.getX() == x && p.getY() == y) return p;
|
if (p.getX() == x && p.getY() == y) return p;
|
||||||
}
|
}
|
||||||
return null;
|
return null;}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue