Added simple (yet surprisingly effective) AI player
+ AIPlayer class + Evaluation method in Board + AI vs AI button in GameModeDialog (produces a rendering delay)
This commit is contained in:
@ -8,6 +8,7 @@ import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import dev.kske.chess.board.Piece.Color;
|
||||
import dev.kske.chess.game.AIPlayer;
|
||||
import dev.kske.chess.game.Game;
|
||||
import dev.kske.chess.game.NaturalPlayer;
|
||||
import dev.kske.chess.game.Player;
|
||||
@ -29,7 +30,7 @@ public class GameModeDialog extends JDialog {
|
||||
super();
|
||||
setModal(true);
|
||||
setTitle("Game Mode Selection");
|
||||
setBounds(100, 100, 231, 99);
|
||||
setBounds(100, 100, 231, 133);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
|
||||
@ -38,12 +39,29 @@ public class GameModeDialog extends JDialog {
|
||||
Map<Color, Player> players = new HashMap<>();
|
||||
players.put(Color.WHITE, new NaturalPlayer(boardPanel.getBoard(), Color.WHITE, boardPanel));
|
||||
players.put(Color.BLACK, new NaturalPlayer(boardPanel.getBoard(), Color.BLACK, boardPanel));
|
||||
new Game(players, boardPanel.getBoard()).start();
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
});
|
||||
getContentPane().add(btnNatural);
|
||||
|
||||
JButton btnAI = new JButton("Game against AI");
|
||||
btnAI.addActionListener((evt) -> {
|
||||
Map<Color, Player> players = new HashMap<>();
|
||||
players.put(Color.WHITE, new NaturalPlayer(boardPanel.getBoard(), Color.WHITE, boardPanel));
|
||||
players.put(Color.BLACK, new AIPlayer(boardPanel.getBoard(), Color.BLACK));
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
});
|
||||
getContentPane().add(btnAI);
|
||||
|
||||
JButton btnAI2 = new JButton("AI against AI");
|
||||
btnAI2.addActionListener((evt) -> {
|
||||
Map<Color, Player> players = new HashMap<>();
|
||||
players.put(Color.WHITE, new AIPlayer(boardPanel.getBoard(), Color.WHITE));
|
||||
players.put(Color.BLACK, new AIPlayer(boardPanel.getBoard(), Color.BLACK));
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
});
|
||||
getContentPane().add(btnAI2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user