1500 let's go
This commit is contained in:
@@ -18,11 +18,11 @@ public class SwingMain {
|
||||
Window window = new Window(commandExecutor, false);
|
||||
commandExecutor.addListener(window);
|
||||
|
||||
AI ai = new AlphaBetaAI(commandExecutor, Color.White, 3);
|
||||
AI ai = new AlphaBetaAI(commandExecutor, Color.Black, 5);
|
||||
commandExecutor.addListener(ai);
|
||||
|
||||
AI ai2 = new AlphaBetaAI(commandExecutor, Color.Black, 3);
|
||||
commandExecutor.addListener(ai2);
|
||||
// AI ai2 = new AlphaBetaAI(commandExecutor, Color.White, 5);
|
||||
// commandExecutor.addListener(ai2);
|
||||
|
||||
// Window window2 = new Window(ai2.getSimulation(), false);
|
||||
// ai2.getSimulation().addListener(window2);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class AlphaBetaAI extends AI {
|
||||
public AlphaBetaAI(CommandExecutor commandExecutor, Color color, int searchDepth) {
|
||||
super(commandExecutor, color);
|
||||
this.searchDepth = searchDepth;
|
||||
int threadCount = Runtime.getRuntime().availableProcessors() / 2;
|
||||
int threadCount = Runtime.getRuntime().availableProcessors();
|
||||
this.threadPool = Executors.newFixedThreadPool(threadCount, new AlphaBetaThreadCreator(commandExecutor, color, threadCount));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,7 @@ public class AlphaBetaThread extends Thread {
|
||||
private final PieceCost pieceCost;
|
||||
private final PiecePosCost piecePosCost;
|
||||
|
||||
private final Color color;
|
||||
|
||||
private static final int GREAT_MOVE = -9999;
|
||||
private static final int HORRIBLE_MOVE = -GREAT_MOVE;
|
||||
private static final int GREAT_MOVE = 9999;
|
||||
|
||||
private static final float MAX_FLOAT = Float.MAX_VALUE;
|
||||
private static final float MIN_FLOAT = -MAX_FLOAT;
|
||||
@@ -33,7 +30,6 @@ public class AlphaBetaThread extends Thread {
|
||||
this.simulation = simulation;
|
||||
this.pieceCost = new PieceCost(color);
|
||||
this.piecePosCost = new PiecePosCost(color);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private float getEndGameEvaluation() {
|
||||
@@ -69,7 +65,7 @@ public class AlphaBetaThread extends Thread {
|
||||
List<Move> moves = this.simulation.getAllowedMoves();
|
||||
|
||||
if (moves.isEmpty())
|
||||
return getEndGameEvaluation();
|
||||
return -getEndGameEvaluation();
|
||||
|
||||
List<Entry<Move, Float>> movesCost = new ArrayList<>(moves.size());
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
import chess.model.Move;
|
||||
import chess.model.PermissiveGame;
|
||||
|
||||
public class GameSimulation extends GameAdaptator {
|
||||
|
||||
@@ -25,7 +26,7 @@ public class GameSimulation extends GameAdaptator {
|
||||
private final Game gameSimulation;
|
||||
|
||||
public GameSimulation() {
|
||||
this.gameSimulation = new Game();
|
||||
this.gameSimulation = new PermissiveGame();
|
||||
this.simulation = new CommandExecutor(gameSimulation, new EmptyGameDispatcher());
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
// we must promote the pending pawn before
|
||||
if (board.pawnShouldBePromoted())
|
||||
if (game.pawnShouldBePromoted())
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
Piece piece = board.pieceAt(move.getStart());
|
||||
|
||||
@@ -122,4 +122,8 @@ public class Game {
|
||||
return this.movesHistory;
|
||||
}
|
||||
|
||||
public boolean pawnShouldBePromoted() {
|
||||
return this.board.pawnShouldBePromoted();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
20
app/src/main/java/chess/model/PermissiveGame.java
Normal file
20
app/src/main/java/chess/model/PermissiveGame.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package chess.model;
|
||||
|
||||
public class PermissiveGame extends Game {
|
||||
|
||||
@Override
|
||||
public GameStatus checkGameStatus(Color color) {
|
||||
return GameStatus.OnGoing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoTraitPiecesPos() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTraitPiecesPos() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user