statistiques de complexite

This commit is contained in:
Antonin Boyon 2021-02-24 15:26:00 +01:00
parent f673ed86fb
commit 56b97547b1
4 changed files with 11 additions and 0 deletions

View File

@ -13,10 +13,13 @@ public class Main {
State game = new State(board, p1, p2); State game = new State(board, p1, p2);
System.out.println("joueur 1: " + p1); System.out.println("joueur 1: " + p1);
System.out.println("joueur 2: " + p2); System.out.println("joueur 2: " + p2);
int tour = 0; // Pour le rapport
while(!game.isOver()) { while(!game.isOver()) {
Player player = game.getCurrentPlayer(); Player player = game.getCurrentPlayer();
System.out.println(game.toString()); System.out.println(game.toString());
game = game.play(player.play(game)); game = game.play(player.play(game));
System.out.println("Tour "+tour+" ; complex : "+player.getComplexity());
tour++;
} }
System.out.println(game.toString()); System.out.println(game.toString());
System.out.println(game.getN1()+" "+ game.getN2()); System.out.println(game.getN1()+" "+ game.getN2());

View File

@ -16,6 +16,7 @@ public class AlphaBetaPlayer extends Player{
Pair<Point, Point> bestMove = null; Pair<Point, Point> bestMove = null;
for(Pair<Point, Point> move : game.getMove(game.getCurrentPlayer())) { for(Pair<Point, Point> move : game.getMove(game.getCurrentPlayer())) {
State nextState = game.play(move); State nextState = game.play(move);
complexity++;
int value = -alphabeta(nextState, this.depth,Integer.MIN_VALUE,Integer.MAX_VALUE); int value = -alphabeta(nextState, this.depth,Integer.MIN_VALUE,Integer.MAX_VALUE);
if (value > bestValue) { if (value > bestValue) {
bestValue = value; bestValue = value;

View File

@ -33,6 +33,7 @@ public class NegamaxPlayer extends Player {
int m = Integer.MIN_VALUE; int m = Integer.MIN_VALUE;
for (Pair<Point, Point> move : state.getMove(state.getCurrentPlayer())) { for (Pair<Point, Point> move : state.getMove(state.getCurrentPlayer())) {
State nextState = state.play(move); State nextState = state.play(move);
complexity++;
m= Math.max(m,-negamax(nextState,depth-1)); m= Math.max(m,-negamax(nextState,depth-1));
} }
return m; return m;

View File

@ -7,9 +7,15 @@ import othello.State;
public abstract class Player { public abstract class Player {
protected final int depth; protected final int depth;
protected int complexity;
public Player(int depth) { public Player(int depth) {
this.depth = depth; this.depth = depth;
this.complexity = 0;
}
public int getComplexity () {
return this.complexity;
} }
public abstract Pair<Point, Point> play(State board); public abstract Pair<Point, Point> play(State board);