From 56b97547b109f34a84fdbef4b60e1e967f231950 Mon Sep 17 00:00:00 2001 From: Antonin Boyon Date: Wed, 24 Feb 2021 15:26:00 +0100 Subject: [PATCH] statistiques de complexite --- src/othello/Main.java | 3 +++ src/othello/players/AlphaBetaPlayer.java | 1 + src/othello/players/NegamaxPlayer.java | 1 + src/othello/players/Player.java | 6 ++++++ 4 files changed, 11 insertions(+) diff --git a/src/othello/Main.java b/src/othello/Main.java index cd4177b..f0eb560 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -13,10 +13,13 @@ public class Main { State game = new State(board, p1, p2); System.out.println("joueur 1: " + p1); System.out.println("joueur 2: " + p2); + int tour = 0; // Pour le rapport while(!game.isOver()) { Player player = game.getCurrentPlayer(); System.out.println(game.toString()); game = game.play(player.play(game)); + System.out.println("Tour "+tour+" ; complex : "+player.getComplexity()); + tour++; } System.out.println(game.toString()); System.out.println(game.getN1()+" "+ game.getN2()); diff --git a/src/othello/players/AlphaBetaPlayer.java b/src/othello/players/AlphaBetaPlayer.java index e0b22b8..d12a9b4 100644 --- a/src/othello/players/AlphaBetaPlayer.java +++ b/src/othello/players/AlphaBetaPlayer.java @@ -16,6 +16,7 @@ public class AlphaBetaPlayer extends Player{ Pair bestMove = null; for(Pair move : game.getMove(game.getCurrentPlayer())) { State nextState = game.play(move); + complexity++; int value = -alphabeta(nextState, this.depth,Integer.MIN_VALUE,Integer.MAX_VALUE); if (value > bestValue) { bestValue = value; diff --git a/src/othello/players/NegamaxPlayer.java b/src/othello/players/NegamaxPlayer.java index 4913acd..82698ad 100644 --- a/src/othello/players/NegamaxPlayer.java +++ b/src/othello/players/NegamaxPlayer.java @@ -33,6 +33,7 @@ public class NegamaxPlayer extends Player { int m = Integer.MIN_VALUE; for (Pair move : state.getMove(state.getCurrentPlayer())) { State nextState = state.play(move); + complexity++; m= Math.max(m,-negamax(nextState,depth-1)); } return m; diff --git a/src/othello/players/Player.java b/src/othello/players/Player.java index f7ee887..8d7fdaf 100644 --- a/src/othello/players/Player.java +++ b/src/othello/players/Player.java @@ -7,9 +7,15 @@ import othello.State; public abstract class Player { protected final int depth; + protected int complexity; public Player(int depth) { this.depth = depth; + this.complexity = 0; + } + + public int getComplexity () { + return this.complexity; } public abstract Pair play(State board);