makefile_compilation_erreur #28
@@ -208,48 +208,76 @@ public class ArenaWindow extends JFrame {
|
|||||||
// Charger le plateau initial
|
// Charger le plateau initial
|
||||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||||
|
|
||||||
// Lancer les parties
|
// Créer un dialogue de progression
|
||||||
for (int i = 1; i <= nbParties; i++) {
|
JDialog progressDialog = new JDialog(this, "Parties en cours...", true);
|
||||||
AvalamBoard board = new AvalamBoard(initialGrid, Player.PLAYER1);
|
JLabel progressLabel = new JLabel("Préparation des parties...", JLabel.CENTER);
|
||||||
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
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 {
|
// Exécuter les parties dans un thread séparé pour ne pas bloquer l'interface
|
||||||
Result result = game.run();
|
Thread arenaThread = new Thread(() -> {
|
||||||
String winner = getWinnerName(result, bot1Type, bot2Type);
|
SwingUtilities.invokeLater(() -> progressDialog.setVisible(true));
|
||||||
|
|
||||||
// Ajouter au tableau
|
for (int i = 1; i <= nbParties; i++) {
|
||||||
tableModel.addRow(new Object[]{
|
final int partieNum = i;
|
||||||
"Partie " + i,
|
SwingUtilities.invokeLater(() -> {
|
||||||
bot1Type,
|
progressLabel.setText("Partie " + partieNum + " / " + nbParties + " en cours...");
|
||||||
bot2Type,
|
|
||||||
winner
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
tableModel.addRow(new Object[]{
|
|
||||||
"Partie " + i,
|
|
||||||
bot1Type,
|
|
||||||
bot2Type,
|
|
||||||
"Erreur: " + e.getMessage()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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
|
// Fermer le dialogue et afficher le message de fin
|
||||||
Object[] options = {"OK", "Quitter le jeu"};
|
SwingUtilities.invokeLater(() -> {
|
||||||
int choice = JOptionPane.showOptionDialog(
|
progressDialog.dispose();
|
||||||
this,
|
|
||||||
"Toutes les parties sont terminées !",
|
Object[] options = {"OK", "Quitter le jeu"};
|
||||||
"Arène terminée",
|
int choice = JOptionPane.showOptionDialog(
|
||||||
JOptionPane.DEFAULT_OPTION,
|
this,
|
||||||
JOptionPane.INFORMATION_MESSAGE,
|
"Toutes les parties sont terminées !",
|
||||||
null,
|
"Arène terminée",
|
||||||
options,
|
JOptionPane.DEFAULT_OPTION,
|
||||||
options[0]
|
JOptionPane.INFORMATION_MESSAGE,
|
||||||
);
|
null,
|
||||||
|
options,
|
||||||
|
options[0]
|
||||||
|
);
|
||||||
|
|
||||||
if (choice == 1) {
|
if (choice == 1) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
arenaThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -105,22 +105,38 @@ public class DivineBot extends AbstractGamePlayer {
|
|||||||
|
|
||||||
boolean isMax = board.getCurrentPlayer() == me;
|
boolean isMax = board.getCurrentPlayer() == me;
|
||||||
|
|
||||||
for (AbstractPly m : listMoves(board)) {
|
List<AbstractPly> moves = listMoves(board);
|
||||||
IBoard next = board.safeCopy();
|
if (moves.isEmpty()) {
|
||||||
next.doPly(m);
|
return evaluate(board);
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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