From f59f9975fa22f462b386d987747e8d2f8beebdee Mon Sep 17 00:00:00 2001 From: vaisse Date: Fri, 6 Feb 2026 01:27:28 +0100 Subject: [PATCH] =?UTF-8?q?c'est=20le=20d=C3=A9sespoir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- javaAPI/fr/iut_fbleau/HexGame/Simulation.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java index 61f26c3..24b5388 100644 --- a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java +++ b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java @@ -3,6 +3,7 @@ package fr.iut_fbleau.HexGame; import fr.iut_fbleau.GameAPI.*; import java.util.EnumMap; import java.util.LinkedList; +import java.util.Random; public class Simulation extends AbstractGame { @@ -27,16 +28,18 @@ public class Simulation extends AbstractGame { //METHODES /*Le jeu de Hex ne peut jamais finir avec le résultat null. En utilisant cette propriété, on peut avoir cet algorithme simplifié du monte-carlo*/ - private float MonteCarlo(HexBoard position){ - RandomBot simplay = new RandomBot(); + private float MonteCarlo(HexBoard position, Player current){ + RandomBot simplay = new RandomBot(current, new Random().nextLong()); HexBoard simpos = position; LinkedList ctaken = taken; HexPly testmove; float wins = 0; float losses = 0; + int count = 0; for(int i=0; i=losses){ - return losses/wins; - } else { - return -(wins/losses); - } + System.out.println(" wins : "+wins+"/losses : "+losses); + System.out.println(" eval : "+(wins-losses)/EVALDEPTH); + + return (wins-losses)/EVALDEPTH; } @@ -66,7 +72,7 @@ public class Simulation extends AbstractGame { } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return MonteCarlo(position); + return MonteCarlo(position, Player.PLAYER1); } else { float bestcase = -1.0f; HexPly bestcasemove; @@ -108,7 +114,7 @@ public class Simulation extends AbstractGame { } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return MonteCarlo(position); + return MonteCarlo(position, Player.PLAYER2); } else { float bestcase = 1.0f; HexPly bestcasemove; @@ -150,7 +156,7 @@ public class Simulation extends AbstractGame { } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return MonteCarlo(position); + return MonteCarlo(position, Player.PLAYER1); } else { float bestcase = A; HexPly bestcasemove; @@ -194,7 +200,7 @@ public class Simulation extends AbstractGame { } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return MonteCarlo(position); + return MonteCarlo(position, Player.PLAYER2); } else { float bestcase = B; HexPly bestcasemove;