Compare commits
2 Commits
e0a2c2642a
...
legitbugfi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe13b946b1 | ||
|
|
c278b18872 |
1
javaAPI/.~lock.arena_results.csv#
Normal file
1
javaAPI/.~lock.arena_results.csv#
Normal file
@@ -0,0 +1 @@
|
|||||||
|
,vaisse,salle235-12,06.02.2026 11:29,file:///export/home/an23/vaisse/.config/libreoffice/4;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
Bot 1, Bot 2, Winner
|
||||||
|
RandomBot,MiniMaxBot,WIN
|
||||||
|
RandomBot,HeuristicBot,WIN
|
||||||
|
RandomBot,MonteCarloBot,WIN
|
||||||
|
MiniMaxBot,HeuristicBot,WIN
|
||||||
|
MiniMaxBot,MonteCarloBot,WIN
|
||||||
|
HeuristicBot,MonteCarloBot,WIN
|
||||||
|
|||||||
|
@@ -26,5 +26,6 @@ public abstract class AbstractGamePlayer {
|
|||||||
* @throws IllegalStateException if the Situation is already in the bookmarks
|
* @throws IllegalStateException if the Situation is already in the bookmarks
|
||||||
*/
|
*/
|
||||||
public abstract AbstractPly giveYourMove(IBoard p);
|
public abstract AbstractPly giveYourMove(IBoard p);
|
||||||
|
public abstract Boolean jesuisMinimax();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ public class Arena {
|
|||||||
|
|
||||||
private List<AbstractGamePlayer> bots = new ArrayList<>();
|
private List<AbstractGamePlayer> bots = new ArrayList<>();
|
||||||
private FileWriter csvWriter;
|
private FileWriter csvWriter;
|
||||||
|
private int board_size;
|
||||||
|
|
||||||
public Arena() {
|
public Arena(int size) {
|
||||||
try {
|
try {
|
||||||
csvWriter = new FileWriter("arena_results.csv");
|
csvWriter = new FileWriter("arena_results.csv");
|
||||||
csvWriter.append("Bot 1, Bot 2, Winner\n");
|
csvWriter.append("Bot 1, Bot 2, Winner\n");
|
||||||
|
this.board_size = size;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -51,12 +53,12 @@ public class Arena {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Result playMatch(AbstractGamePlayer bot1, AbstractGamePlayer bot2) {
|
private Result playMatch(AbstractGamePlayer bot1, AbstractGamePlayer bot2) {
|
||||||
IBoard board = new HexBoard(11);
|
IBoard board = new HexBoard(this.board_size);
|
||||||
EnumMap<Player, AbstractGamePlayer> players = new EnumMap<>(Player.class);
|
EnumMap<Player, AbstractGamePlayer> players = new EnumMap<>(Player.class);
|
||||||
players.put(Player.PLAYER1, bot1);
|
players.put(Player.PLAYER1, bot1);
|
||||||
players.put(Player.PLAYER2, bot2);
|
players.put(Player.PLAYER2, bot2);
|
||||||
|
|
||||||
Simulation simulation = new Simulation(board, players);
|
Simulation simulation = new Simulation(board, players);
|
||||||
return simulation.run();
|
return simulation.runForArena();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import fr.iut_fbleau.GameAPI.Player;
|
|||||||
|
|
||||||
public class ArenaMain {
|
public class ArenaMain {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Arena arena = new Arena();
|
int size = 7;
|
||||||
arena.addBot(new RandomBot(Player.PLAYER1, 12345L)); // Correct constructor usage
|
if (args.length >= 1) {
|
||||||
|
try { size = Integer.parseInt(args[0]); } catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
Arena arena = new Arena(size);
|
||||||
|
arena.addBot(new RandomBot(Player.PLAYER1, 24015L)); // Correct constructor usage
|
||||||
arena.addBot(new MiniMaxBot(Player.PLAYER2));
|
arena.addBot(new MiniMaxBot(Player.PLAYER2));
|
||||||
arena.addBot(new HeuristicBot(Player.PLAYER1));
|
arena.addBot(new HeuristicBot(Player.PLAYER1));
|
||||||
arena.addBot(new MonteCarloBot(Player.PLAYER2)); // Correct constructor usage
|
arena.addBot(new MonteCarloBot(Player.PLAYER2)); // Correct constructor usage
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ public class HeuristicBot extends AbstractGamePlayer {
|
|||||||
super(me); // Correct constructor usage
|
super(me); // Correct constructor usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean jesuisMinimax(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractPly giveYourMove(IBoard board) {
|
public AbstractPly giveYourMove(IBoard board) {
|
||||||
HexBoard hb = (HexBoard) board;
|
HexBoard hb = (HexBoard) board;
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ public class HumanConsolePlayer extends AbstractGamePlayer {
|
|||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean jesuisMinimax(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractPly giveYourMove(IBoard board) {
|
public AbstractPly giveYourMove(IBoard board) {
|
||||||
if (!(board instanceof HexBoard)) {
|
if (!(board instanceof HexBoard)) {
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ public class MiniMaxBot extends AbstractGamePlayer {
|
|||||||
super(me); // Correct constructor usage
|
super(me); // Correct constructor usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean jesuisMinimax(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractPly giveYourMove(IBoard board) {
|
public AbstractPly giveYourMove(IBoard board) {
|
||||||
HexBoard hb = (HexBoard) board;
|
HexBoard hb = (HexBoard) board;
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ public class MonteCarloBot extends AbstractGamePlayer {
|
|||||||
super(me); // Correct constructor usage
|
super(me); // Correct constructor usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean jesuisMinimax(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractPly giveYourMove(IBoard board) {
|
public AbstractPly giveYourMove(IBoard board) {
|
||||||
HexBoard hb = (HexBoard) board;
|
HexBoard hb = (HexBoard) board;
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ public class RandomBot extends AbstractGamePlayer {
|
|||||||
this.rng = rng;
|
this.rng = rng;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean jesuisMinimax(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public RandomBot(Player me, long seed) {
|
public RandomBot(Player me, long seed) {
|
||||||
this(me, new Random(seed));
|
this(me, new Random(seed));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ public class Simulation extends AbstractGame {
|
|||||||
ctaken = taken;
|
ctaken = taken;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
System.out.println(" wins : "+wins+"/losses : "+losses);
|
//System.out.println(" wins : "+wins+"/losses : "+losses);
|
||||||
System.out.println(" eval : "+(wins-losses)/EVALDEPTH);
|
//System.out.println(" eval : "+(wins-losses)/EVALDEPTH);
|
||||||
return (wins-losses)/EVALDEPTH;
|
return (wins-losses)/EVALDEPTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,9 +232,7 @@ public class Simulation extends AbstractGame {
|
|||||||
}
|
}
|
||||||
return bestcase;
|
return bestcase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private AbstractPly GiveBestMove(IBoard board) {
|
private AbstractPly GiveBestMove(IBoard board) {
|
||||||
@@ -269,5 +267,27 @@ public class Simulation extends AbstractGame {
|
|||||||
return simCurrentBoard.getResult();
|
return simCurrentBoard.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result runForArena(){
|
||||||
|
while(!simCurrentBoard.isGameOver()){
|
||||||
|
AbstractGamePlayer player = simmapPlayers.get(simCurrentBoard.getCurrentPlayer());
|
||||||
|
IBoard board = simCurrentBoard.safeCopy();
|
||||||
|
AbstractPly ply;
|
||||||
|
if(player.jesuisMinimax()){
|
||||||
|
ply = GiveBestMove(board);
|
||||||
|
} else {
|
||||||
|
ply = player.giveYourMove(board);
|
||||||
|
}
|
||||||
|
HexPly concretePly = (HexPly) ply;
|
||||||
|
|
||||||
|
if (simCurrentBoard.isLegal(ply)) {
|
||||||
|
simCurrentBoard.doPly(ply);
|
||||||
|
taken.add(new Integer[]{concretePly.getRow(), concretePly.getCol()});
|
||||||
|
System.out.println("Player "+player+" goes ("+concretePly.getRow()+","+concretePly.getCol()+")");
|
||||||
|
}
|
||||||
|
else throw new IllegalStateException("Player "+ player + " is a bloody cheat. He tried playing : "+concretePly.getRow()+","+concretePly.getCol()+" I give up.");
|
||||||
|
}
|
||||||
|
return simCurrentBoard.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user