thread pool + ai vs ai
This commit is contained in:
@@ -44,10 +44,13 @@ public class Window extends JFrame implements GameListener {
|
||||
private final JButton bigCastlingButton = new JButton("Grand Roque");
|
||||
private final JButton undoButton = new JButton("Annuler le coup précédent");
|
||||
|
||||
public Window(CommandExecutor commandExecutor) {
|
||||
private final boolean showPopups;
|
||||
|
||||
public Window(CommandExecutor commandExecutor, boolean showPopups) {
|
||||
this.cells = new JLabel[8][8];
|
||||
this.displayText = new JLabel();
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.showPopups = showPopups;
|
||||
setSize(800, 910);
|
||||
setVisible(true);
|
||||
setLocationRelativeTo(null);
|
||||
@@ -198,15 +201,6 @@ public class Window extends JFrame implements GameListener {
|
||||
@Override
|
||||
public void playerTurn(chess.model.Color color) {
|
||||
this.displayText.setText("Current turn: " + color);
|
||||
|
||||
// dumb IA
|
||||
if (color == chess.model.Color.Black) {
|
||||
GetPlayerMovesCommand cmd = new GetPlayerMovesCommand();
|
||||
sendCommand(cmd);
|
||||
List<Move> moves = cmd.getMoves();
|
||||
int random = new Random().nextInt(moves.size());
|
||||
sendCommand(new MoveCommand(moves.get(random)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,6 +213,8 @@ public class Window extends JFrame implements GameListener {
|
||||
|
||||
@Override
|
||||
public void kingIsInCheck() {
|
||||
if (!showPopups)
|
||||
return;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(this, "Check!");
|
||||
});
|
||||
@@ -252,39 +248,39 @@ public class Window extends JFrame implements GameListener {
|
||||
|
||||
@Override
|
||||
public void promotePawn(Coordinate pieceCoords) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
String result = null;
|
||||
// SwingUtilities.invokeLater(() -> {
|
||||
// String result = null;
|
||||
|
||||
Object[] possibilities = new Object[PromoteType.values().length];
|
||||
int i = 0;
|
||||
for (PromoteType type : PromoteType.values()) {
|
||||
possibilities[i] = type.name();
|
||||
i++;
|
||||
}
|
||||
// Object[] possibilities = new Object[PromoteType.values().length];
|
||||
// int i = 0;
|
||||
// for (PromoteType type : PromoteType.values()) {
|
||||
// possibilities[i] = type.name();
|
||||
// i++;
|
||||
// }
|
||||
|
||||
while (result == null || result.isEmpty()) {
|
||||
result = (String) JOptionPane.showInputDialog(
|
||||
this,
|
||||
"Choose the type of piece to upgrade the pawn",
|
||||
"Promote Dialog",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
possibilities,
|
||||
possibilities[0]);
|
||||
}
|
||||
// while (result == null || result.isEmpty()) {
|
||||
// result = (String) JOptionPane.showInputDialog(
|
||||
// this,
|
||||
// "Choose the type of piece to upgrade the pawn",
|
||||
// "Promote Dialog",
|
||||
// JOptionPane.PLAIN_MESSAGE,
|
||||
// null,
|
||||
// possibilities,
|
||||
// possibilities[0]);
|
||||
// }
|
||||
|
||||
PromoteType choosedType = null;
|
||||
// PromoteType choosedType = null;
|
||||
|
||||
for (PromoteType type : PromoteType.values()) {
|
||||
if (type.name().equals(result)) {
|
||||
choosedType = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for (PromoteType type : PromoteType.values()) {
|
||||
// if (type.name().equals(result)) {
|
||||
// choosedType = type;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (choosedType != null)
|
||||
sendCommand(new PromoteCommand(choosedType));
|
||||
});
|
||||
// if (choosedType != null)
|
||||
// sendCommand(new PromoteCommand(choosedType));
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user