truc fonctionnel mais avec un retouchage dans l'API. dsl
This commit is contained in:
@@ -59,6 +59,6 @@ public class Arena {
|
||||
players.put(Player.PLAYER2, bot2);
|
||||
|
||||
Simulation simulation = new Simulation(board, players);
|
||||
return simulation.run();
|
||||
return simulation.runForArena();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -232,9 +232,7 @@ public class Simulation extends AbstractGame {
|
||||
}
|
||||
return bestcase;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private AbstractPly GiveBestMove(IBoard board) {
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user