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/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..bf58cf0 --- /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 = 6; + 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