Compare commits
15 Commits
quitter_re
...
af70986edd
| Author | SHA1 | Date | |
|---|---|---|---|
| af70986edd | |||
|
|
d94b95fa36 | ||
|
|
2db0212b31 | ||
|
|
43e44bf7d2 | ||
| 023aa9d419 | |||
| 2cf929e024 | |||
|
|
ee374a9221 | ||
| 1eddda2605 | |||
| 8bbe17ebd8 | |||
| f43361a48f | |||
| ad2f0c63cf | |||
| dea162182b | |||
| c0cd120b1e | |||
| fa578b86d2 | |||
| 14e5df4332 |
3
Diagrammes/Diagramme - Avalam.svg
Normal file
3
Diagrammes/Diagramme - Avalam.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 128 KiB |
3
Diagrammes/Diagramme - Bot.svg
Normal file
3
Diagrammes/Diagramme - Bot.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 22 KiB |
3
Diagrammes/Diagramme - GameAPI.svg
Normal file
3
Diagrammes/Diagramme - GameAPI.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 40 KiB |
@@ -3,6 +3,28 @@ title: Avalam - Diagramme de classes (complet)
|
||||
---
|
||||
classDiagram
|
||||
|
||||
class ArenaGame{
|
||||
+ArenaGame(IBoard board, AbstractGamePlayer bot1, AbstractGamePlayer bot2)
|
||||
-createPlayerMap(AbstractGamePlayer bot1, AbstractGamePlayer bot2): EnumMap<Player, AbstractGamePlayer>
|
||||
}
|
||||
|
||||
class ArenaWindow{
|
||||
-resultsTable: JTable
|
||||
-tableModel: DefaultTableModel
|
||||
-results: List<string>
|
||||
|
||||
+ArenaWindows()
|
||||
-createConfigPanel(): JPanel
|
||||
-createResultsTable()
|
||||
-showConfigDialog()
|
||||
-runArena(String bot1Type, String bot2Type, int depth, int nbParties)
|
||||
-createBot(String botType, Player player, int depth): AbstractGamePlayer
|
||||
-getWinnerName(Result result, String bot1Type, String bot2Type): String
|
||||
}
|
||||
|
||||
ArenaWindow *-- AvalamBoard
|
||||
ArenaWindow *-- ArenaGame
|
||||
|
||||
class AvalamBoard{
|
||||
+SIZE: int
|
||||
-MAX_HEIGHT: int
|
||||
@@ -43,8 +65,6 @@ classDiagram
|
||||
+toString(): String
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AvalamWindow{
|
||||
-board : AvalamBoard
|
||||
-scoreView : ScoreView
|
||||
@@ -70,14 +90,19 @@ classDiagram
|
||||
AvalamWindow *-- BoardView
|
||||
AvalamWindow *-- ScoreView
|
||||
AvalamWindow *-- TurnView
|
||||
AvalamWindow *-- EndGameDialog
|
||||
AvalamWindow --> GameMode
|
||||
|
||||
class BackgroundLayer{
|
||||
-img: Image
|
||||
+BackgroundLayer(String resourcePath)
|
||||
#paintComponent(Graphics g): void
|
||||
}
|
||||
|
||||
class BoardLoader{
|
||||
+loadFromFile(String resourcePath): Tower[][]
|
||||
}
|
||||
|
||||
|
||||
|
||||
class BoardView{
|
||||
-board: AvalamBoard
|
||||
-backgroundLayer: BackgroundLayer
|
||||
@@ -105,14 +130,6 @@ classDiagram
|
||||
BoardView *-- InteractionController
|
||||
BoardView --> AvalamBoard
|
||||
|
||||
class BackgroundLayer{
|
||||
-img: Image
|
||||
+BackgroundLayer(String resourcePath)
|
||||
#paintComponent(Graphics g): void
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Color{
|
||||
-YELLOW(int r, int g, int b)
|
||||
-RED(int r, int g, int b)
|
||||
@@ -122,11 +139,17 @@ classDiagram
|
||||
+toPlayer(): fr.iut_fbleau.GameAPI.Player
|
||||
}
|
||||
|
||||
class EndGameDialog{
|
||||
+EndGameDialog(JFrame parent, Result result, int scoreJaune, int scoreRouge, GameMode mode, int depth, Runnable onReplay, Runnable onMenu, Runnable onQuit)
|
||||
-modeToString(GameMode mode, int depth): String
|
||||
}
|
||||
|
||||
class GameMode{
|
||||
PVP
|
||||
PVBOT
|
||||
PVALPHA
|
||||
PVGOD
|
||||
ARENA
|
||||
}
|
||||
|
||||
class HighlightLayer{
|
||||
@@ -165,6 +188,7 @@ classDiagram
|
||||
|
||||
Main ..> AvalamWindow
|
||||
Main ..> GameMode
|
||||
Main ..> ArenaWindow
|
||||
|
||||
class PieceButton{
|
||||
-color: java.awt.Color
|
||||
|
||||
@@ -17,7 +17,16 @@ classDiagram
|
||||
}
|
||||
|
||||
class DivineBot{
|
||||
-me: Player
|
||||
-maxDepth: int
|
||||
-rng: Random
|
||||
|
||||
+DivineBot(Player p, int maxDepth)
|
||||
+giveYourMove(IBoard board): AbstractPly
|
||||
-alphaBeta(IBoard board, int depth, int alpha, int beta): int
|
||||
-terminalValue(IBoard board): int
|
||||
-evaluate(IBoard board): int
|
||||
-listMoves(IBoard board): List<AbstractPly>
|
||||
}
|
||||
|
||||
class IdiotBot{
|
||||
|
||||
54
Makefile
54
Makefile
@@ -1,3 +1,8 @@
|
||||
# === Environnements ===
|
||||
JUNIT_JAR = /usr/share/java/junit.jar
|
||||
HAMCREST_JAR = /usr/share/java/hamcrest-core.jar
|
||||
TEST_ENV = "bin:$(JUNIT_JAR):$(HAMCREST_JAR)"
|
||||
|
||||
# === Répertoires ===
|
||||
SRC_DIR = fr
|
||||
BIN_DIR = bin
|
||||
@@ -6,18 +11,28 @@ BIN_DIR = bin
|
||||
RES_SRC = fr/iut_fbleau/Res
|
||||
RES_BIN = bin/fr/iut_fbleau/Res
|
||||
|
||||
# === Recherche automatique des fichiers .java dans tous les sous-dossiers ===
|
||||
SOURCES := $(shell find $(SRC_DIR) -name "*.java")
|
||||
# === Recherche automatique des fichiers .java ===
|
||||
# SOURCES : uniquement le code de l'application (sans les fichiers de tests)
|
||||
SOURCES := $(shell find $(SRC_DIR) -name "*.java" -not -path "$(SRC_DIR)/iut_fbleau/Tests/*")
|
||||
# TEST_SOURCES : uniquement les fichiers de tests
|
||||
TEST_SOURCES := $(shell find $(SRC_DIR)/iut_fbleau/Tests -name "*.java" 2>/dev/null)
|
||||
|
||||
# === Classe principale ===
|
||||
MAIN_CLASS = fr.iut_fbleau.Avalam.Main
|
||||
|
||||
# === Classe de test ===
|
||||
TEST_CLASS = fr.iut_fbleau.Tests.AvalamBoardTest
|
||||
|
||||
# === Commandes Java ===
|
||||
JC = javac
|
||||
# Compilation normale (application uniquement)
|
||||
JCFLAGS = -d $(BIN_DIR)
|
||||
# Compilation des tests (application + JUnit)
|
||||
JCFLAGS_TESTS = -d $(BIN_DIR) -cp $(TEST_ENV)
|
||||
|
||||
JAVA = java
|
||||
JAVAFLAGS = -cp $(BIN_DIR)
|
||||
JAVAFLAGS_TESTS = -cp $(TEST_ENV)
|
||||
|
||||
# === Règle par défaut ===
|
||||
all: build
|
||||
@@ -31,6 +46,35 @@ compile:
|
||||
@mkdir -p $(BIN_DIR)
|
||||
@$(JC) $(JCFLAGS) $(SOURCES)
|
||||
|
||||
compile_tests: compile
|
||||
@echo "===> Compilation des tests..."
|
||||
@mkdir -p $(BIN_DIR)
|
||||
ifneq ($(TEST_SOURCES),)
|
||||
@$(JC) $(JCFLAGS_TESTS) $(TEST_SOURCES)
|
||||
else
|
||||
@echo "Aucun fichier de test trouvé dans $(SRC_DIR)/iut_fbleau/Tests"
|
||||
endif
|
||||
|
||||
# === Vérification / installation des dépendances de tests ===
|
||||
check_test_deps:
|
||||
@echo "===> Vérification des dépendances de tests (JUnit / Hamcrest)..."
|
||||
@if [ ! -f "$(JUNIT_JAR)" ] || [ ! -f "$(HAMCREST_JAR)" ]; then \
|
||||
echo " JUnit ou Hamcrest manquant, tentative d'installation (sudo requis)..."; \
|
||||
if command -v sudo >/dev/null 2>&1; then \
|
||||
sudo apt-get update && sudo apt-get install -y junit4 libhamcrest-java; \
|
||||
else \
|
||||
apt-get update && apt-get install -y junit4 libhamcrest-java; \
|
||||
fi; \
|
||||
if [ ! -f "$(JUNIT_JAR)" ] || [ ! -f "$(HAMCREST_JAR)" ]; then \
|
||||
echo "✖ Impossible de trouver/installer $(JUNIT_JAR) ou $(HAMCREST_JAR). Vérifiez manuellement vos paquets JUnit/Hamcrest."; \
|
||||
exit 1; \
|
||||
else \
|
||||
echo "✔ Dépendances de tests installées."; \
|
||||
fi; \
|
||||
else \
|
||||
echo "✔ JUnit et Hamcrest trouvés."; \
|
||||
fi
|
||||
|
||||
# === Copie des ressources (.txt) dans bin ===
|
||||
resources:
|
||||
@echo "===> Copie des ressources..."
|
||||
@@ -43,6 +87,12 @@ run:
|
||||
@echo "===> Lancement du jeu Avalam..."
|
||||
@$(JAVA) $(JAVAFLAGS) $(MAIN_CLASS)
|
||||
|
||||
# === Tests ===
|
||||
test: check_test_deps compile_tests
|
||||
@echo "===> Lancement des tests..."
|
||||
@$(JAVA) $(JAVAFLAGS_TESTS) org.junit.runner.JUnitCore $(TEST_CLASS)
|
||||
@echo "... Fin des tests."
|
||||
|
||||
# === Nettoyage ===
|
||||
clean:
|
||||
@echo "===> Suppression des fichiers compilés..."
|
||||
|
||||
41
README.md
41
README.md
@@ -4,38 +4,63 @@
|
||||
|
||||
Date de création : 16/10/25
|
||||
|
||||
Le but est de mettre en oeuvre des jeux plus intéressants que le jeu de Nim, toujours en suivant l'API.
|
||||
Date de rendu : 06/02/26
|
||||
|
||||
Dans un second temps, on fera des bots le plus efficace possible (probablement un alpha beta avec cut-off plus fonction d'évaluation qui peut être faite à la main ou par MonteCarlo).
|
||||
Le but est de mettre en oeuvre un jeu plus intéressants que le jeu de Nim, en suivant l'API de Florent Madelaine.
|
||||
|
||||
Dans un second temps, nous développerons des bots les plus efficaces possible, probablement en utilisant un algorithme alpha-bêta avec cut-off et une fonction d'évaluation réalisé à la main ou par MonteCarlo.
|
||||
|
||||
Le jeu de notre groupe est **Avalam**.
|
||||
|
||||
## Compilation et exécution
|
||||
## Compilation, exécution et tests
|
||||
|
||||
### Compilation
|
||||
### Compilation (sans tests)
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
ou simplement :
|
||||
```bash
|
||||
make
|
||||
```
|
||||
Cette commande :
|
||||
- compile uniquement le code de l'application (sans les fichiers du dossier `fr/iut_fbleau/Tests`) ;
|
||||
- copie les ressources dans `bin/`.
|
||||
|
||||
### Exécution
|
||||
### Exécution du jeu
|
||||
```bash
|
||||
make run
|
||||
```
|
||||
Lance la fenêtre de jeu Avalam après compilation.
|
||||
|
||||
### Lancer les tests
|
||||
```bash
|
||||
make test
|
||||
```
|
||||
Cette commande :
|
||||
- vérifie d'abord la présence de **JUnit** et **Hamcrest** dans `/usr/share/java` ;
|
||||
- si nécessaire, tente de les installer automatiquement via `apt-get` (sudo requis sur Debian/Ubuntu) ;
|
||||
- compile ensuite les fichiers de tests (`fr/iut_fbleau/Tests`) ;
|
||||
- lance enfin la suite de tests JUnit (`AvalamBoardTest`).
|
||||
|
||||
Si l'installation automatique échoue (autre OS, pas de droits sudo, pas d'accès réseau, etc.), un message l'indiquera et il faudra installer JUnit/Hamcrest manuellement.
|
||||
|
||||
### Nettoyage
|
||||
```bash
|
||||
make clean
|
||||
```
|
||||
Supprime le répertoire `bin/` (classes compilées et ressources copiées).
|
||||
|
||||
### Recompiler et exécuter
|
||||
### Recompiler puis exécuter
|
||||
```bash
|
||||
make re
|
||||
```
|
||||
Équivaut à `make clean` puis `make build` puis `make run`.
|
||||
|
||||
### Générer la Javadoc
|
||||
```bash
|
||||
make javadoc
|
||||
```
|
||||
Génère la documentation dans le dossier `doc/`.
|
||||
|
||||
## Architecture du projet
|
||||
|
||||
@@ -78,13 +103,13 @@ Le plateau est représenté par une grille 9x9 où chaque case contient :
|
||||
|
||||
Sur un plateau de jeu, les joueurs disposent de 24 pions chacun. Le but est de créer de petites tours avec son pion de couleur au-dessus. Pour ce faire, chaque joueur déplace son pion sur une tour ou déplace une tour sur un autre pion. La personne ayant le plus de pions sur le dessus des tours gagne.
|
||||
|
||||
### Régles officiel :
|
||||
### Règles officielles :
|
||||
**Régle de base** \
|
||||
Chaque joueur choisit sa couleur.
|
||||
Le but du jeu est de constituer un maximum de tours de 1 à 5 pions, jamais plus, surmontées par un pion de sa couleur.
|
||||
Un joueur est le propriétaire d'une tour lorsqu'un pion de sa couleur en occupe le sommet. Un pion isolé constitue également une tour.
|
||||
|
||||
**Deplacements** \
|
||||
**Déplacements** \
|
||||
Chaque joueur en effectue un seul mouvement, dans n'importe quel sens (horizontal, vertical, diagonal) avec n'importe quel pion (ou pile de pions), quelle qu'en soit la couleur. Ce mouvement consiste à empiler le ou les pions déplacés sur un trou directement voisin déjà occupé par un ou plusieurs pions.
|
||||
|
||||
**Mouvement interdit (1)** \
|
||||
|
||||
@@ -192,24 +192,55 @@ public class ArenaWindow extends JFrame {
|
||||
* @param nbParties nombre de parties à jouer
|
||||
*/
|
||||
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
|
||||
tableModel.setRowCount(0);
|
||||
results.clear();
|
||||
|
||||
// Charger le plateau initial
|
||||
Tower[][] initialGrid = BoardLoader.loadFromFile("fr/iut_fbleau/Res/Plateau.txt");
|
||||
// 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);
|
||||
|
||||
// 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++) {
|
||||
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);
|
||||
ArenaGame game = new ArenaGame(board, bot1, bot2);
|
||||
|
||||
@@ -217,28 +248,64 @@ public class ArenaWindow extends JFrame {
|
||||
Result result = game.run();
|
||||
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[]{
|
||||
"Partie " + i,
|
||||
"Partie " + partieNum,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
winner
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
errors++;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
tableModel.addRow(new Object[]{
|
||||
"Partie " + i,
|
||||
"Partie " + partieNum,
|
||||
bot1Type,
|
||||
bot2Type,
|
||||
"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"};
|
||||
int choice = JOptionPane.showOptionDialog(
|
||||
this,
|
||||
"Toutes les parties sont terminées !",
|
||||
statsMessage,
|
||||
"Arène terminée",
|
||||
JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.INFORMATION_MESSAGE,
|
||||
@@ -250,6 +317,10 @@ public class ArenaWindow extends JFrame {
|
||||
if (choice == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
arenaThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,9 +51,16 @@ public class AvalamBoard extends AbstractBoard {
|
||||
super(startingPlayer, new ArrayDeque<>());
|
||||
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 c = 0; c < SIZE; c++)
|
||||
this.grid[r][c] = initialGrid[r][c];
|
||||
for (int c = 0; c < SIZE; 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,6 +212,7 @@ public class AvalamBoard extends AbstractBoard {
|
||||
Tower dst = grid[xT][yT];
|
||||
if (src == null || dst == null) return false;
|
||||
|
||||
if (p.getPlayer() != getCurrentPlayer()) return false;
|
||||
if (src.getColor() != colorForPlayer(getCurrentPlayer())) return false;
|
||||
if (!areAdjacent(xF, yF, xT, yT)) return false;
|
||||
if (src.getColor() == dst.getColor()) return false;
|
||||
|
||||
@@ -233,7 +233,6 @@ public class AvalamWindow extends JFrame {
|
||||
} else if (mode == GameMode.PVALPHA) {
|
||||
botMove = alphaBot.giveYourMove(board.safeCopy());
|
||||
} else {
|
||||
// A FAIRE PLUS TARD (PVGOD)
|
||||
botMove = divineBot.giveYourMove(board.safeCopy());
|
||||
}
|
||||
|
||||
|
||||
@@ -105,22 +105,38 @@ public class DivineBot extends AbstractGamePlayer {
|
||||
|
||||
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();
|
||||
next.doPly(m);
|
||||
|
||||
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
|
||||
}
|
||||
return best;
|
||||
} 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
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
return isMax ? alpha : beta;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
123
fr/iut_fbleau/Tests/AvalamBoardTest.java
Normal file
123
fr/iut_fbleau/Tests/AvalamBoardTest.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package fr.iut_fbleau.Tests;
|
||||
|
||||
import fr.iut_fbleau.GameAPI.AbstractPly;
|
||||
import fr.iut_fbleau.GameAPI.Player;
|
||||
|
||||
import fr.iut_fbleau.Avalam.AvalamBoard;
|
||||
import fr.iut_fbleau.Avalam.AvalamPly;
|
||||
import fr.iut_fbleau.Avalam.Tower;
|
||||
import fr.iut_fbleau.Avalam.Color;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
//import org.mockito.Mockito; //Mockito absent
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* La classe <code>AvalamBoardTest</code> test si la méthode isLegal() fonctionne comme prévu.
|
||||
*/
|
||||
public class AvalamBoardTest {
|
||||
|
||||
private Tower[][] grid;
|
||||
private AvalamBoard board;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
grid = new Tower[AvalamBoard.SIZE][AvalamBoard.SIZE];
|
||||
|
||||
//Création des tours de tests
|
||||
/* Motif
|
||||
1,0,2 | 2,0,3
|
||||
2,1,0 | 2,3,0
|
||||
0,2,1 | 0,1,1
|
||||
*/
|
||||
grid[4][2] = new Tower(2, Color.YELLOW);
|
||||
grid[6][2] = new Tower(3, Color.RED);
|
||||
|
||||
grid[4][3] = new Tower(2, Color.RED);
|
||||
grid[5][3] = new Tower(3, Color.YELLOW);
|
||||
|
||||
grid[5][4] = new Tower(1, Color.RED);
|
||||
grid[6][4] = new Tower(1, Color.YELLOW);
|
||||
|
||||
//Joueur courant initialisé à 1, soit jaune
|
||||
board = new AvalamBoard(grid); //AvalamBoard copie la grille
|
||||
}
|
||||
|
||||
/*
|
||||
@Test //Mockito absent
|
||||
public void nonAvalamPly_returnsFalse() {
|
||||
//Vérifie si l'instance est bien AvalamPly
|
||||
AbstractPly fake = Mockito.mock(AbstractPly.class); //Crée une instance non-AvalamPly
|
||||
assertFalse(board.isLegal(fake));
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void outOfBounds_returnsFalse() {
|
||||
//Source "out of box"
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, -1, 2, 4, 2);
|
||||
assertFalse(board.isLegal(p));
|
||||
|
||||
//Destination "out of box"
|
||||
AvalamPly p2 = new AvalamPly(Player.PLAYER1, 6, 4, 9, 4);
|
||||
assertFalse(board.isLegal(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameCell_returnsFalse() {
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 4, 5, 4);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySourceOrDest_returnsFalse() {
|
||||
//Source null
|
||||
AvalamPly p1 = new AvalamPly(Player.PLAYER1, 5, 5, 5, 4);
|
||||
assertFalse(board.isLegal(p1));
|
||||
|
||||
//Destination null
|
||||
AvalamPly p2 = new AvalamPly(Player.PLAYER1, 6, 4, 6, 3);
|
||||
assertFalse(board.isLegal(p2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceNotOwned_returnsFalse() {
|
||||
//Le joueur courant n'est pas rouge
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 4, 6, 4);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notAdjacent_returnsFalse() {
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 4, 2, 6, 2);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameColor_returnsFalse() {
|
||||
//La couleur des tours est identique
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 4, 2, 5, 3);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tooTallAfterMerge_returnsFalse() {
|
||||
//Hauteur maximale dépassé : 3+3 = 6 > MAX_HEIGHT (5)
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 3, 6, 2);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validMove_returnsTrue() {
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 3, 4, 3); //Hauteur limite à 5
|
||||
assertTrue(board.isLegal(p));
|
||||
}
|
||||
|
||||
@Test //À vérifier
|
||||
public void currentPlayerMismatchInPlyDoesNotAffectOwnershipCheck() {
|
||||
//Si le coup est construit avec le mauvais joueur
|
||||
AvalamPly p = new AvalamPly(Player.PLAYER2, 4, 2, 4, 3);
|
||||
assertFalse(board.isLegal(p));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user