From a7d3e9d138852fc57c035156ccdf0c9e7f5c9145 Mon Sep 17 00:00:00 2001 From: vaisse Date: Wed, 21 Jan 2026 17:20:06 +0100 Subject: [PATCH 1/2] =?UTF-8?q?impl=C3=A9mentation=20de=20l'algo=20fonctio?= =?UTF-8?q?nnelle.=20Reste=20=C3=A0=20faire=20un=20code=20qui=20=C3=A9valu?= =?UTF-8?q?e=20une=20position?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- javaAPI/fr/iut_fbleau/HexGame/HexMain.java | 12 +- javaAPI/fr/iut_fbleau/HexGame/Simulation.java | 145 ++++++++++++++++++ 2 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 javaAPI/fr/iut_fbleau/HexGame/Simulation.java diff --git a/javaAPI/fr/iut_fbleau/HexGame/HexMain.java b/javaAPI/fr/iut_fbleau/HexGame/HexMain.java index e9d3885..df307da 100644 --- a/javaAPI/fr/iut_fbleau/HexGame/HexMain.java +++ b/javaAPI/fr/iut_fbleau/HexGame/HexMain.java @@ -1,7 +1,6 @@ package fr.iut_fbleau.HexGame; import fr.iut_fbleau.GameAPI.*; - import java.util.EnumMap; import java.util.Scanner; @@ -19,12 +18,19 @@ public class HexMain { HexBoard board = new HexBoard(size); Scanner sc = new Scanner(System.in); + Result res; EnumMap players = new EnumMap<>(Player.class); players.put(Player.PLAYER1, new HumanConsolePlayer(Player.PLAYER1, sc)); players.put(Player.PLAYER2, new HumanConsolePlayer(Player.PLAYER2, sc)); - AbstractGame game = new AbstractGame(board, players) {}; - Result res = game.run(); + + if (args.length>=2 && args[1].equals("autoplay")) { + Simulation sim = new Simulation(board, players); + res = sim.run(); + } else { + AbstractGame game = new AbstractGame(board, players) {}; + res = game.run(); + } System.out.println(board); System.out.println("Résultat (du point de vue de PLAYER1) : " + res); diff --git a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java new file mode 100644 index 0000000..85b1b0c --- /dev/null +++ b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java @@ -0,0 +1,145 @@ +package fr.iut_fbleau.HexGame; + +import fr.iut_fbleau.GameAPI.*; +import java.util.EnumMap; +import java.util.LinkedList; + + +public class Simulation extends AbstractGame { + + //ATTRIBUTS + private HexPly bestmove; + private float bestoutcome; + private int MAXDEPTH = 5; + private LinkedList taken = new LinkedList(); + + //ATTRIBUTS QUE JE NE VOUDRAIS PAS CRÉER IDÉALEMENT + private IBoard simCurrentBoard; + private EnumMap simmapPlayers; + + //CONSTRUCTEUR + public Simulation(IBoard b, EnumMap m){ + super(b, m); + simCurrentBoard = b; + simmapPlayers = m; + } + + //METHODES + 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; + } else { + float bestcase = -1.0f; + 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; + } + } + position.undoPly(); + taken.remove(t); + } + } + } + return bestcase; + } + } + + + private float explMIN(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; + } else { + float bestcase = 1.0f; + HexPly bestcasemove; + HexPly testmove; + for (int i=0; i Date: Fri, 30 Jan 2026 09:32:17 +0100 Subject: [PATCH 2/2] AUTOPLAY une nouvellle fois --- javaAPI/fr/iut_fbleau/GameAPI/AbstractGame.java | 4 ++-- javaAPI/fr/iut_fbleau/HexGame/Simulation.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javaAPI/fr/iut_fbleau/GameAPI/AbstractGame.java b/javaAPI/fr/iut_fbleau/GameAPI/AbstractGame.java index 55a6acc..489610e 100644 --- a/javaAPI/fr/iut_fbleau/GameAPI/AbstractGame.java +++ b/javaAPI/fr/iut_fbleau/GameAPI/AbstractGame.java @@ -34,8 +34,8 @@ public abstract class AbstractGame { // constructeur à appeler dans le constructeur d'un fils concret avec super. public AbstractGame(IBoard b, EnumMap m){ - this.currentBoard=b; - this.mapPlayers=m; + this.currentBoard=b; + this.mapPlayers=m; } /** diff --git a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java index 85b1b0c..bf58cf0 100644 --- a/javaAPI/fr/iut_fbleau/HexGame/Simulation.java +++ b/javaAPI/fr/iut_fbleau/HexGame/Simulation.java @@ -10,7 +10,7 @@ public class Simulation extends AbstractGame { //ATTRIBUTS private HexPly bestmove; private float bestoutcome; - private int MAXDEPTH = 5; + private int MAXDEPTH = 6; private LinkedList taken = new LinkedList(); //ATTRIBUTS QUE JE NE VOUDRAIS PAS CRÉER IDÉALEMENT -- 2.52.0