From 4b2b37a04a7c0613ac0cb965649a1a0285af7fed Mon Sep 17 00:00:00 2001 From: vaisse Date: Tue, 3 Feb 2026 11:54:49 +0100 Subject: [PATCH] =?UTF-8?q?j'ai=20=C3=A9crit=20des=20trucs,=20mais=20il=20?= =?UTF-8?q?faut=20encore=20tester?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- javaAPI/fr/iut_fbleau/HexGame/Simulation.java | 136 +++++++++++++++++- 1 file changed, 131 insertions(+), 5 deletions(-) diff --git a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java index bf58cf0..49c34ca 100644 --- a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java +++ b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java @@ -10,7 +10,8 @@ public class Simulation extends AbstractGame { //ATTRIBUTS private HexPly bestmove; private float bestoutcome; - private int MAXDEPTH = 6; + private int MAXDEPTH = 9; + private int EVALDEPTH = 10; private LinkedList taken = new LinkedList(); //ATTRIBUTS QUE JE NE VOUDRAIS PAS CRÉER IDÉALEMENT @@ -25,13 +26,47 @@ 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(); + HexBoard simpos = position.safeCopy(); + LinkedList ctaken = taken; + HexPly testmove; + float wins = 0; + float losses = 0; + + for(int i=0; i=losses){ + return losses/wins; + } else { + return -(wins/losses); + } + + } + private float explMAX(HexBoard position, int depth){ if (position.getResult()==Result.LOSS) { return -1.0f; } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return 0f; + return MonteCarlo(position); } else { float bestcase = -1.0f; HexPly bestcasemove; @@ -73,7 +108,7 @@ public class Simulation extends AbstractGame { } else if (position.getResult()==Result.WIN){ return 1.0f; } else if (depth==MAXDEPTH) { - return 0f; + return MonteCarlo(position); } else { float bestcase = 1.0f; HexPly bestcasemove; @@ -109,6 +144,97 @@ public class Simulation extends AbstractGame { } } + private float explMAXAB(HexBoard position, int depth, float A, float B){ + if (position.getResult()==Result.LOSS) { + return -1.0f; + } else if (position.getResult()==Result.WIN){ + return 1.0f; + } else if (depth==MAXDEPTH) { + return MonteCarlo(position); + } else { + float bestcase = A; + HexPly bestcasemove; + HexPly testmove; + for (int i=0; i= bestcase) { + //System.out.println(" MAX new best case"); + bestcase = val; + bestcasemove = testmove; + if (depth==0) { + this.bestoutcome = bestcase; + this.bestmove = bestcasemove; + } + if(bestcase>=B){ + return bestcase; + } + } + position.undoPly(); + taken.remove(t); + } + } + } + return bestcase; + } + } + + private float explMINAB(HexBoard position, int depth, A, B){ + if (position.getResult()==Result.LOSS) { + return -1.0f; + } else if (position.getResult()==Result.WIN){ + return 1.0f; + } else if (depth==MAXDEPTH) { + return MonteCarlo(position); + } else { + float bestcase = B; + HexPly bestcasemove; + HexPly testmove; + for (int i=0; i