ajout d'une fenetre arene et bug divinebot
This commit is contained in:
@@ -208,48 +208,76 @@ public class ArenaWindow extends JFrame {
|
||||
// Charger le plateau initial
|
||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||
|
||||
// Lancer les parties
|
||||
for (int i = 1; i <= nbParties; i++) {
|
||||
AvalamBoard board = new AvalamBoard(initialGrid, Player.PLAYER1);
|
||||
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
||||
// Créer un dialogue de progression
|
||||
JDialog progressDialog = new JDialog(this, "Parties en cours...", true);
|
||||
JLabel progressLabel = new JLabel("Préparation des parties...", JLabel.CENTER);
|
||||
progressLabel.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 40));
|
||||
progressDialog.add(progressLabel);
|
||||
progressDialog.setSize(300, 100);
|
||||
progressDialog.setLocationRelativeTo(this);
|
||||
progressDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
try {
|
||||
Result result = game.run();
|
||||
String winner = getWinnerName(result, bot1Type, bot2Type);
|
||||
|
||||
// Ajouter au tableau
|
||||
tableModel.addRow(new Object[]{
|
||||
"Partie " + i,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
winner
|
||||
});
|
||||
} catch (Exception e) {
|
||||
tableModel.addRow(new Object[]{
|
||||
"Partie " + i,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
"Erreur: " + e.getMessage()
|
||||
// Exécuter les parties dans un thread séparé pour ne pas bloquer l'interface
|
||||
Thread arenaThread = new Thread(() -> {
|
||||
SwingUtilities.invokeLater(() -> progressDialog.setVisible(true));
|
||||
|
||||
for (int i = 1; i <= nbParties; i++) {
|
||||
final int partieNum = i;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
progressLabel.setText("Partie " + partieNum + " / " + nbParties + " en cours...");
|
||||
});
|
||||
|
||||
AvalamBoard board = new AvalamBoard(initialGrid, Player.PLAYER1);
|
||||
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
||||
|
||||
try {
|
||||
Result result = game.run();
|
||||
String winner = getWinnerName(result, bot1Type, bot2Type);
|
||||
|
||||
// Ajouter au tableau dans le thread EDT
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
tableModel.addRow(new Object[]{
|
||||
"Partie " + partieNum,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
winner
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
tableModel.addRow(new Object[]{
|
||||
"Partie " + partieNum,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
"Erreur: " + e.getMessage()
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Afficher un message de fin avec possibilité de quitter directement
|
||||
Object[] options = {"OK", "Quitter le jeu"};
|
||||
int choice = JOptionPane.showOptionDialog(
|
||||
this,
|
||||
"Toutes les parties sont terminées !",
|
||||
"Arène terminée",
|
||||
JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]
|
||||
);
|
||||
// Fermer le dialogue et afficher le message de fin
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
progressDialog.dispose();
|
||||
|
||||
Object[] options = {"OK", "Quitter le jeu"};
|
||||
int choice = JOptionPane.showOptionDialog(
|
||||
this,
|
||||
"Toutes les parties sont terminées !",
|
||||
"Arène terminée",
|
||||
JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]
|
||||
);
|
||||
|
||||
if (choice == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
if (choice == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
arenaThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,22 +105,38 @@ public class DivineBot extends AbstractGamePlayer {
|
||||
|
||||
boolean isMax = board.getCurrentPlayer() == me;
|
||||
|
||||
for (AbstractPly m : listMoves(board)) {
|
||||
IBoard next = board.safeCopy();
|
||||
next.doPly(m);
|
||||
|
||||
int val = alphaBeta(next, depth - 1, alpha, beta);
|
||||
|
||||
if (isMax) {
|
||||
alpha = Math.max(alpha, val);
|
||||
if (alpha >= beta) break; // Coupure Beta
|
||||
} else {
|
||||
beta = Math.min(beta, val);
|
||||
if (alpha >= beta) break; // Coupure Alpha
|
||||
}
|
||||
List<AbstractPly> moves = listMoves(board);
|
||||
if (moves.isEmpty()) {
|
||||
return evaluate(board);
|
||||
}
|
||||
|
||||
return isMax ? alpha : beta;
|
||||
if (isMax) {
|
||||
int best = Integer.MIN_VALUE;
|
||||
for (AbstractPly m : moves) {
|
||||
IBoard next = board.safeCopy();
|
||||
next.doPly(m);
|
||||
|
||||
int val = alphaBeta(next, depth - 1, alpha, beta);
|
||||
best = Math.max(best, val);
|
||||
alpha = Math.max(alpha, best);
|
||||
|
||||
if (alpha >= beta) break; // Coupure Beta
|
||||
}
|
||||
return best;
|
||||
} else {
|
||||
int best = Integer.MAX_VALUE;
|
||||
for (AbstractPly m : moves) {
|
||||
IBoard next = board.safeCopy();
|
||||
next.doPly(m);
|
||||
|
||||
int val = alphaBeta(next, depth - 1, alpha, beta);
|
||||
best = Math.min(best, val);
|
||||
beta = Math.min(beta, best);
|
||||
|
||||
if (alpha >= beta) break; // Coupure Alpha
|
||||
}
|
||||
return best;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user