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