Commit 1206c04c authored by TRAN Alain's avatar TRAN Alain

Replace AlgoRechercheMinMax.java

parent 9da78a8c
...@@ -24,7 +24,7 @@ public class AlgoRechercheMinMax extends AlgoRecherche { ...@@ -24,7 +24,7 @@ public class AlgoRechercheMinMax extends AlgoRecherche {
} }
String[][] grille = {{"","",""},{"","",""},{"","",""}}; String[][] grille = {{"","",""},{"","",""},{"","",""}};
double[] scores = {1,-1,0}; double[] scores = {-1,1,0};
@Override @Override
public Coup meilleurCoup(Plateau _plateau, Joueur _joueur, boolean ponder){ public Coup meilleurCoup(Plateau _plateau, Joueur _joueur, boolean ponder){
...@@ -34,14 +34,16 @@ public class AlgoRechercheMinMax extends AlgoRecherche { ...@@ -34,14 +34,16 @@ public class AlgoRechercheMinMax extends AlgoRecherche {
ArrayList<Coup> coups = _plateau.getListeCoups(ordi); ArrayList<Coup> coups = _plateau.getListeCoups(ordi);
for (int i = 0; i < coups.size(); i++){ for (int i = 0; i < coups.size(); i++){
_plateau.sauvegardePosition(0);
_plateau.joueCoup(coups.get(i)); _plateau.joueCoup(coups.get(i));
System.out.println(_plateau); //System.out.println(_plateau);
System.out.println("coup initial"); //System.out.println("coup initial");
double score = minimax(_plateau,humain,0,false); //False car l'ordi a déjà placé son premier coup double score = minimax(_plateau,humain,1,false); //False car l'ordi a déjà placé son premier coup
Coup coup_provisoire = coups.get(i); Coup coup_provisoire = coups.get(i);
_plateau.annuleDernierCoup(); // _plateau.annuleDernierCoup();
System.out.println("annule coup initial"); _plateau.restaurePosition(0);
System.out.println(_plateau); //System.out.println("annule coup initial");
//System.out.println(_plateau);
if (score > bestScore){ if (score > bestScore){
bestScore = score; bestScore = score;
meilleur_coup = (CoupTicTacToe)coup_provisoire; meilleur_coup = (CoupTicTacToe)coup_provisoire;
...@@ -68,15 +70,17 @@ public class AlgoRechercheMinMax extends AlgoRecherche { ...@@ -68,15 +70,17 @@ public class AlgoRechercheMinMax extends AlgoRecherche {
double bestScore = -1 * inf; double bestScore = -1 * inf;
ArrayList<Coup> coups = _plateau.getListeCoups(ordi); ArrayList<Coup> coups = _plateau.getListeCoups(ordi);
for (int i = 0; i < coups.size(); i++){ for (int i = 0; i < coups.size(); i++){
_plateau.sauvegardePosition(profondeur);
_plateau.joueCoup(coups.get(i)); _plateau.joueCoup(coups.get(i));
System.out.println(_plateau); //System.out.println(_plateau);
System.out.println("coup ordi"); //System.out.println("coup ordi");
double score = minimax(_plateau,humain,profondeur + 1,false); double score = minimax(_plateau,humain,profondeur + 1,false);
System.out.println("dernier coup " + _plateau.getDernierCoup()); //System.out.println("dernier coup " + _plateau.getDernierCoup());
_plateau.annuleDernierCoup(); //_plateau.annuleDernierCoup();
System.out.println(_plateau); _plateau.restaurePosition(profondeur);
System.out.println("coup ordi annulé"); //System.out.println(_plateau);
System.out.println("dernier coup " + _plateau.getDernierCoup()); //System.out.println("coup ordi annulé");
//System.out.println("dernier coup " + _plateau.getDernierCoup());
bestScore = max(score,bestScore); bestScore = max(score,bestScore);
} }
return bestScore; return bestScore;
...@@ -86,15 +90,17 @@ public class AlgoRechercheMinMax extends AlgoRecherche { ...@@ -86,15 +90,17 @@ public class AlgoRechercheMinMax extends AlgoRecherche {
double bestScore = inf; double bestScore = inf;
ArrayList<Coup> coups = _plateau.getListeCoups(humain); ArrayList<Coup> coups = _plateau.getListeCoups(humain);
for (int i = 0; i < coups.size(); i++){ for (int i = 0; i < coups.size(); i++){
_plateau.joueCoup(coups.get(i)); // problème : Il faut que ce soit l'autre joueur qui joue ici _plateau.sauvegardePosition(profondeur);
System.out.println(_plateau); _plateau.joueCoup(coups.get(i));
System.out.println("coup humain"); //System.out.println(_plateau);
//System.out.println("coup humain");
double score = minimax(_plateau,ordi,profondeur + 1,true); double score = minimax(_plateau,ordi,profondeur + 1,true);
System.out.println("dernier coup " + _plateau.getDernierCoup()); //System.out.println("dernier coup " + _plateau.getDernierCoup());
_plateau.annuleDernierCoup(); //_plateau.annuleDernierCoup();
System.out.println(_plateau); _plateau.restaurePosition(profondeur);
System.out.println("coup humain annulé"); //System.out.println(_plateau);
System.out.println("dernier coup " + _plateau.getDernierCoup()); //System.out.println("coup humain annulé");
//System.out.println("dernier coup " + _plateau.getDernierCoup());
bestScore = min(score,bestScore); bestScore = min(score,bestScore);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment