legitbugfix #19

Open
Alistair VAISSE wants to merge 10 commits from legitbugfix into master
10 changed files with 49 additions and 7 deletions
Showing only changes of commit fe13b946b1 - Show all commits

View File

@@ -0,0 +1 @@
,vaisse,salle235-12,06.02.2026 11:29,file:///export/home/an23/vaisse/.config/libreoffice/4;

View File

@@ -26,5 +26,6 @@ public abstract class AbstractGamePlayer {
* @throws IllegalStateException if the Situation is already in the bookmarks
*/
public abstract AbstractPly giveYourMove(IBoard p);
public abstract Boolean jesuisMinimax();
}

View File

@@ -59,6 +59,6 @@ public class Arena {
players.put(Player.PLAYER2, bot2);
Simulation simulation = new Simulation(board, players);
return simulation.run();
return simulation.runForArena();
}
}

View File

@@ -9,7 +9,7 @@ public class ArenaMain {
try { size = Integer.parseInt(args[0]); } catch (NumberFormatException ignored) {}
}
Arena arena = new Arena(size);
arena.addBot(new RandomBot(Player.PLAYER1, 12345L)); // Correct constructor usage
arena.addBot(new RandomBot(Player.PLAYER1, 24015L)); // Correct constructor usage
arena.addBot(new MiniMaxBot(Player.PLAYER2));
arena.addBot(new HeuristicBot(Player.PLAYER1));
arena.addBot(new MonteCarloBot(Player.PLAYER2)); // Correct constructor usage

View File

@@ -8,6 +8,10 @@ public class HeuristicBot extends AbstractGamePlayer {
super(me); // Correct constructor usage
}
public Boolean jesuisMinimax(){
return false;
}
@Override
public AbstractPly giveYourMove(IBoard board) {
HexBoard hb = (HexBoard) board;

View File

@@ -18,6 +18,10 @@ public class HumanConsolePlayer extends AbstractGamePlayer {
this.in = in;
}
public Boolean jesuisMinimax(){
return false;
}
@Override
public AbstractPly giveYourMove(IBoard board) {
if (!(board instanceof HexBoard)) {

View File

@@ -10,6 +10,10 @@ public class MiniMaxBot extends AbstractGamePlayer {
super(me); // Correct constructor usage
}
public Boolean jesuisMinimax(){
return true;
}
@Override
public AbstractPly giveYourMove(IBoard board) {
HexBoard hb = (HexBoard) board;

View File

@@ -12,6 +12,10 @@ public class MonteCarloBot extends AbstractGamePlayer {
super(me); // Correct constructor usage
}
public Boolean jesuisMinimax(){
return false;
}
@Override
public AbstractPly giveYourMove(IBoard board) {
HexBoard hb = (HexBoard) board;

View File

@@ -19,6 +19,10 @@ public class RandomBot extends AbstractGamePlayer {
this.rng = rng;
}
public Boolean jesuisMinimax(){
return false;
}
public RandomBot(Player me, long seed) {
this(me, new Random(seed));
}

View File

@@ -57,8 +57,8 @@ public class Simulation extends AbstractGame {
ctaken = taken;
count = 0;
}
System.out.println(" wins : "+wins+"/losses : "+losses);
System.out.println(" eval : "+(wins-losses)/EVALDEPTH);
//System.out.println(" wins : "+wins+"/losses : "+losses);
//System.out.println(" eval : "+(wins-losses)/EVALDEPTH);
return (wins-losses)/EVALDEPTH;
}
@@ -235,8 +235,6 @@ public class Simulation extends AbstractGame {
}
private AbstractPly GiveBestMove(IBoard board) {
if (!(board instanceof HexBoard)) {
throw new IllegalArgumentException("Ce joueur attend un HexBoard.");
@@ -269,5 +267,27 @@ public class Simulation extends AbstractGame {
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();
}
}