pretty convincing

This commit is contained in:
2025-04-18 23:51:42 +02:00
parent dd6e033528
commit 031d3d94ec
6 changed files with 146 additions and 12 deletions

View File

@@ -17,11 +17,13 @@ import chess.model.Color;
import chess.model.Coordinate;
import chess.model.Game;
import chess.model.Move;
import chess.model.Piece;
public class AlphaBetaAI extends AI {
private final int searchDepth;
private final PieceCost pieceCost;
private final PiecePosCost piecePosCost;
private final CommandExecutor simulation;
private final Game gameSimulation;
@@ -32,6 +34,7 @@ public class AlphaBetaAI extends AI {
super(commandExecutor, color);
this.searchDepth = searchDepth;
this.pieceCost = new PieceCost(color);
this.piecePosCost = new PiecePosCost(color);
this.gameSimulation = new Game();
this.simulation = new CommandExecutor(this.gameSimulation, new EmptyGameDispatcher());
}
@@ -45,7 +48,9 @@ public class AlphaBetaAI extends AI {
int result = 0;
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
result += pieceCost.getCost(board.pieceAt(new Coordinate(i, j)));
Coordinate coordinate = new Coordinate(i, j);
Piece piece = board.pieceAt(coordinate);
result += pieceCost.getCost(piece) + piecePosCost.getEvaluation(piece, coordinate);
}
}
if (this.gameSimulation.getPlayerTurn() != color)
@@ -60,7 +65,7 @@ public class AlphaBetaAI extends AI {
} else {
if (this.gameSimulation.getBoard().isKingInCheck(currentTurn))
return GREAT_MOVE;
return getBoardEvaluation() - PieceCost.PAWN;
return getBoardEvaluation() + PieceCost.PAWN;
}
}