2026-02-05 16:27:10 +01:00
|
|
|
package fr.iut_fbleau.HexGame;
|
|
|
|
|
|
|
|
|
|
import fr.iut_fbleau.GameAPI.*;
|
|
|
|
|
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.EnumMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class Arena {
|
|
|
|
|
|
|
|
|
|
private List<AbstractGamePlayer> bots = new ArrayList<>();
|
|
|
|
|
private FileWriter csvWriter;
|
2026-02-06 11:25:47 +01:00
|
|
|
private int board_size;
|
2026-02-05 16:27:10 +01:00
|
|
|
|
2026-02-06 11:25:47 +01:00
|
|
|
public Arena(int size) {
|
2026-02-05 16:27:10 +01:00
|
|
|
try {
|
|
|
|
|
csvWriter = new FileWriter("arena_results.csv");
|
|
|
|
|
csvWriter.append("Bot 1, Bot 2, Winner\n");
|
2026-02-06 11:25:47 +01:00
|
|
|
this.board_size = size;
|
2026-02-05 16:27:10 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addBot(AbstractGamePlayer bot) {
|
|
|
|
|
bots.add(bot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
for (int i = 0; i < bots.size(); i++) {
|
|
|
|
|
for (int j = i + 1; j < bots.size(); j++) {
|
|
|
|
|
AbstractGamePlayer bot1 = bots.get(i);
|
|
|
|
|
AbstractGamePlayer bot2 = bots.get(j);
|
|
|
|
|
|
|
|
|
|
System.out.println("Running match: " + bot1.getClass().getSimpleName() + " vs " + bot2.getClass().getSimpleName());
|
|
|
|
|
Result result = playMatch(bot1, bot2);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
csvWriter.append(bot1.getClass().getSimpleName() + "," + bot2.getClass().getSimpleName() + "," + result + "\n");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
csvWriter.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Result playMatch(AbstractGamePlayer bot1, AbstractGamePlayer bot2) {
|
2026-02-06 11:25:47 +01:00
|
|
|
IBoard board = new HexBoard(this.board_size);
|
2026-02-05 16:27:10 +01:00
|
|
|
EnumMap<Player, AbstractGamePlayer> players = new EnumMap<>(Player.class);
|
|
|
|
|
players.put(Player.PLAYER1, bot1);
|
|
|
|
|
players.put(Player.PLAYER2, bot2);
|
|
|
|
|
|
2026-02-06 09:31:37 +01:00
|
|
|
Simulation simulation = new Simulation(board, players);
|
2026-02-05 16:27:10 +01:00
|
|
|
return simulation.run();
|
|
|
|
|
}
|
|
|
|
|
}
|