diff --git a/app/src/main/java/chess/SwingMain.java b/app/src/main/java/chess/SwingMain.java index b52dc41..52f087c 100644 --- a/app/src/main/java/chess/SwingMain.java +++ b/app/src/main/java/chess/SwingMain.java @@ -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); diff --git a/app/src/main/java/chess/ai/minimax/AlphaBetaAI.java b/app/src/main/java/chess/ai/minimax/AlphaBetaAI.java index 56e987a..98cef39 100644 --- a/app/src/main/java/chess/ai/minimax/AlphaBetaAI.java +++ b/app/src/main/java/chess/ai/minimax/AlphaBetaAI.java @@ -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)); } diff --git a/app/src/main/java/chess/ai/minimax/AlphaBetaThread.java b/app/src/main/java/chess/ai/minimax/AlphaBetaThread.java index 6e3e515..7657037 100644 --- a/app/src/main/java/chess/ai/minimax/AlphaBetaThread.java +++ b/app/src/main/java/chess/ai/minimax/AlphaBetaThread.java @@ -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 moves = this.simulation.getAllowedMoves(); if (moves.isEmpty()) - return getEndGameEvaluation(); + return -getEndGameEvaluation(); List> movesCost = new ArrayList<>(moves.size()); diff --git a/app/src/main/java/chess/ai/minimax/GameSimulation.java b/app/src/main/java/chess/ai/minimax/GameSimulation.java index 1fb42c6..9520b05 100644 --- a/app/src/main/java/chess/ai/minimax/GameSimulation.java +++ b/app/src/main/java/chess/ai/minimax/GameSimulation.java @@ -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()); } diff --git a/app/src/main/java/chess/controller/commands/MoveCommand.java b/app/src/main/java/chess/controller/commands/MoveCommand.java index 7116690..08a957b 100644 --- a/app/src/main/java/chess/controller/commands/MoveCommand.java +++ b/app/src/main/java/chess/controller/commands/MoveCommand.java @@ -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()); diff --git a/app/src/main/java/chess/model/Game.java b/app/src/main/java/chess/model/Game.java index 360a5d2..28be020 100644 --- a/app/src/main/java/chess/model/Game.java +++ b/app/src/main/java/chess/model/Game.java @@ -122,4 +122,8 @@ public class Game { return this.movesHistory; } + public boolean pawnShouldBePromoted() { + return this.board.pawnShouldBePromoted(); + } + } diff --git a/app/src/main/java/chess/model/PermissiveGame.java b/app/src/main/java/chess/model/PermissiveGame.java new file mode 100644 index 0000000..3554ee4 --- /dev/null +++ b/app/src/main/java/chess/model/PermissiveGame.java @@ -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() { + + } + +} diff --git a/app/src/main/resources/games/wendy.pgn b/app/src/main/resources/games/wendy.pgn new file mode 100644 index 0000000..50a9e72 --- /dev/null +++ b/app/src/main/resources/games/wendy.pgn @@ -0,0 +1,12 @@ +1. e4 {1.e4 $1 A fiery start $1} 1... e5 {I like how this game is starting $1} 2. Nc3 +Bc5 {J'aime un feu chaud.} 3. Nf3 {It's too cold in here for my liking.} 3... +Qf6 4. Nd5 Qd6 5. d3 c6 {A fiery position is what I seek $1} 6. Nc3 h6 7. a3 Qg6 +8. Nxe5 {Things are beginning to heat up, non $2} 8... Qd6 9. Nc4 Qe6 10. d4 Be7 +11. Ne3 b5 12. Nf5 d5 13. Nxg7+ {That's not very nice.} 13... Kd7 14. Nxe6 +{Brrrrrr. It is getting cold in here.} 14... fxe6 15. exd5 cxd5 16. Bf4 Nf6 17. +Bxb5+ Kd8 18. Qf3 Bd7 19. Be5 {My attack is getting cold, I need to go get some +more firewood $1} 19... a6 20. Bxf6 Re8 21. Bxe7+ Kxe7 22. Nxd5+ exd5 23. Qxd5 +Kf8+ {It's getting toasty in here $1} 24. Be2 Bc6 25. Qd6+ Re7 26. Kf1 Ba4 27. b3 +Nc6 28. bxa4 a5 29. Qxc6 Rd8 30. Qxh6+ Kg8 31. Bc4+ Rf7 32. Qg5+ Kh8 33. Bxf7 +{C'est très, très mauvais $1} 33... Kh7 34. Qg6+ Kh8 35. Ra2 Rxd4 36. Qg8# {Good +play $1 I'll have to throw another log on the fire and try again.} 1-0 \ No newline at end of file