Compare commits
3 Commits
023aa9d419
...
makefile_c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d94b95fa36 | ||
|
|
2db0212b31 | ||
|
|
43e44bf7d2 |
@@ -192,24 +192,55 @@ public class ArenaWindow extends JFrame {
|
|||||||
* @param nbParties nombre de parties à jouer
|
* @param nbParties nombre de parties à jouer
|
||||||
*/
|
*/
|
||||||
private void runArena(String bot1Type, String bot2Type, int depth, int nbParties) {
|
private void runArena(String bot1Type, String bot2Type, int depth, int nbParties) {
|
||||||
// Créer les bots
|
|
||||||
AbstractGamePlayer bot1 = createBot(bot1Type, Player.PLAYER1, depth);
|
|
||||||
AbstractGamePlayer bot2 = createBot(bot2Type, Player.PLAYER2, depth);
|
|
||||||
|
|
||||||
if (bot1 == null || bot2 == null) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Erreur lors de la création des bots.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vider le tableau
|
// Vider le tableau
|
||||||
tableModel.setRowCount(0);
|
tableModel.setRowCount(0);
|
||||||
results.clear();
|
results.clear();
|
||||||
|
|
||||||
// Charger le plateau initial
|
// Créer un dialogue de progression
|
||||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
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);
|
||||||
|
|
||||||
|
// Exécuter les parties dans un thread séparé pour ne pas bloquer l'interface
|
||||||
|
Thread arenaThread = new Thread(() -> {
|
||||||
|
SwingUtilities.invokeLater(() -> progressDialog.setVisible(true));
|
||||||
|
|
||||||
|
// Statistiques pour déboguer
|
||||||
|
int bot1Wins = 0;
|
||||||
|
int bot2Wins = 0;
|
||||||
|
int draws = 0;
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
// Lancer les parties
|
|
||||||
for (int i = 1; i <= nbParties; i++) {
|
for (int i = 1; i <= nbParties; i++) {
|
||||||
|
final int partieNum = i;
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
progressLabel.setText("Partie " + partieNum + " / " + nbParties + " en cours...");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recréer les bots à chaque partie pour garantir l'indépendance complète
|
||||||
|
// (notamment pour réinitialiser les générateurs aléatoires)
|
||||||
|
AbstractGamePlayer bot1 = createBot(bot1Type, Player.PLAYER1, depth);
|
||||||
|
AbstractGamePlayer bot2 = createBot(bot2Type, Player.PLAYER2, depth);
|
||||||
|
|
||||||
|
if (bot1 == null || bot2 == null) {
|
||||||
|
errors++;
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
tableModel.addRow(new Object[]{
|
||||||
|
"Partie " + partieNum,
|
||||||
|
bot1Type,
|
||||||
|
bot2Type,
|
||||||
|
"Erreur: Impossible de créer les bots"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recharger le plateau à chaque partie pour garantir l'indépendance complète
|
||||||
|
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||||
AvalamBoard board = new AvalamBoard(initialGrid, Player.PLAYER1);
|
AvalamBoard board = new AvalamBoard(initialGrid, Player.PLAYER1);
|
||||||
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
||||||
|
|
||||||
@@ -217,28 +248,64 @@ public class ArenaWindow extends JFrame {
|
|||||||
Result result = game.run();
|
Result result = game.run();
|
||||||
String winner = getWinnerName(result, bot1Type, bot2Type);
|
String winner = getWinnerName(result, bot1Type, bot2Type);
|
||||||
|
|
||||||
// Ajouter au tableau
|
// Mettre à jour les statistiques
|
||||||
|
if (result == Result.WIN) {
|
||||||
|
bot1Wins++;
|
||||||
|
} else if (result == Result.LOSS) {
|
||||||
|
bot2Wins++;
|
||||||
|
} else if (result == Result.DRAW) {
|
||||||
|
draws++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter au tableau dans le thread EDT
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
tableModel.addRow(new Object[]{
|
tableModel.addRow(new Object[]{
|
||||||
"Partie " + i,
|
"Partie " + partieNum,
|
||||||
bot1Type,
|
bot1Type,
|
||||||
bot2Type,
|
bot2Type,
|
||||||
winner
|
winner
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
errors++;
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
tableModel.addRow(new Object[]{
|
tableModel.addRow(new Object[]{
|
||||||
"Partie " + i,
|
"Partie " + partieNum,
|
||||||
bot1Type,
|
bot1Type,
|
||||||
bot2Type,
|
bot2Type,
|
||||||
"Erreur: " + e.getMessage()
|
"Erreur: " + e.getMessage()
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un message de fin avec possibilité de quitter directement
|
// Afficher les statistiques finales
|
||||||
|
final int finalBot1Wins = bot1Wins;
|
||||||
|
final int finalBot2Wins = bot2Wins;
|
||||||
|
final int finalDraws = draws;
|
||||||
|
final int finalErrors = errors;
|
||||||
|
|
||||||
|
// Fermer le dialogue et afficher le message de fin avec statistiques
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
progressDialog.dispose();
|
||||||
|
|
||||||
|
String statsMessage = String.format(
|
||||||
|
"Toutes les parties sont terminées !\n\n" +
|
||||||
|
"Statistiques :\n" +
|
||||||
|
"- %s (Bot 1) : %d victoires\n" +
|
||||||
|
"- %s (Bot 2) : %d victoires\n" +
|
||||||
|
"- Matchs nuls : %d\n" +
|
||||||
|
"- Erreurs : %d",
|
||||||
|
bot1Type, finalBot1Wins,
|
||||||
|
bot2Type, finalBot2Wins,
|
||||||
|
finalDraws,
|
||||||
|
finalErrors
|
||||||
|
);
|
||||||
|
|
||||||
Object[] options = {"OK", "Quitter le jeu"};
|
Object[] options = {"OK", "Quitter le jeu"};
|
||||||
int choice = JOptionPane.showOptionDialog(
|
int choice = JOptionPane.showOptionDialog(
|
||||||
this,
|
this,
|
||||||
"Toutes les parties sont terminées !",
|
statsMessage,
|
||||||
"Arène terminée",
|
"Arène terminée",
|
||||||
JOptionPane.DEFAULT_OPTION,
|
JOptionPane.DEFAULT_OPTION,
|
||||||
JOptionPane.INFORMATION_MESSAGE,
|
JOptionPane.INFORMATION_MESSAGE,
|
||||||
@@ -250,6 +317,10 @@ public class ArenaWindow extends JFrame {
|
|||||||
if (choice == 1) {
|
if (choice == 1) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
arenaThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,9 +51,16 @@ public class AvalamBoard extends AbstractBoard {
|
|||||||
super(startingPlayer, new ArrayDeque<>());
|
super(startingPlayer, new ArrayDeque<>());
|
||||||
this.grid = new Tower[SIZE][SIZE];
|
this.grid = new Tower[SIZE][SIZE];
|
||||||
|
|
||||||
|
// Copie profonde : créer de nouvelles tours pour éviter que toutes les parties partagent les mêmes objets
|
||||||
for (int r = 0; r < SIZE; r++)
|
for (int r = 0; r < SIZE; r++)
|
||||||
for (int c = 0; c < SIZE; c++)
|
for (int c = 0; c < SIZE; c++) {
|
||||||
this.grid[r][c] = initialGrid[r][c];
|
Tower t = initialGrid[r][c];
|
||||||
|
if (t == null) {
|
||||||
|
this.grid[r][c] = null;
|
||||||
|
} else {
|
||||||
|
this.grid[r][c] = new Tower(t.getHeight(), t.getColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ public class AvalamWindow extends JFrame {
|
|||||||
} else if (mode == GameMode.PVALPHA) {
|
} else if (mode == GameMode.PVALPHA) {
|
||||||
botMove = alphaBot.giveYourMove(board.safeCopy());
|
botMove = alphaBot.giveYourMove(board.safeCopy());
|
||||||
} else {
|
} else {
|
||||||
// A FAIRE PLUS TARD (PVGOD)
|
|
||||||
botMove = divineBot.giveYourMove(board.safeCopy());
|
botMove = divineBot.giveYourMove(board.safeCopy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
if (moves.isEmpty()) {
|
||||||
|
return evaluate(board);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMax) {
|
||||||
|
int best = Integer.MIN_VALUE;
|
||||||
|
for (AbstractPly m : moves) {
|
||||||
IBoard next = board.safeCopy();
|
IBoard next = board.safeCopy();
|
||||||
next.doPly(m);
|
next.doPly(m);
|
||||||
|
|
||||||
int val = alphaBeta(next, depth - 1, alpha, beta);
|
int val = alphaBeta(next, depth - 1, alpha, beta);
|
||||||
|
best = Math.max(best, val);
|
||||||
|
alpha = Math.max(alpha, best);
|
||||||
|
|
||||||
if (isMax) {
|
|
||||||
alpha = Math.max(alpha, val);
|
|
||||||
if (alpha >= beta) break; // Coupure Beta
|
if (alpha >= beta) break; // Coupure Beta
|
||||||
|
}
|
||||||
|
return best;
|
||||||
} else {
|
} else {
|
||||||
beta = Math.min(beta, val);
|
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
|
if (alpha >= beta) break; // Coupure Alpha
|
||||||
}
|
}
|
||||||
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isMax ? alpha : beta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user