Commit 9a4d46c0 authored by Theo Delbecq's avatar Theo Delbecq

Resolution manuelle du conflit sur ArbreMinMax en local

parents 2b9f32ea 5464252f
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Arbre.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Arbre.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/AlgoRecherche.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/AlgoRecherche.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/JoueurHumain.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/JoueurHumain.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/AlgoRechercheMinMax.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Jeton.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Jeton.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Case.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/Case.java</file>
<file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/ArbreMinMax.java</file> <file>file:/C:/Users/theo/Documents/Ecole/IMT%20Lille%20Douai/L3/Projet%20Info/groupe3-tictactoe/src/tictactoecodingame/ArbreMinMax.java</file>
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tictactoecodingame;
import java.util.ArrayList;
/**
*
* @author Théo
*/
public class AlgoRechercheMinMax extends AlgoRecherche{
/*La profondeur de recherche demandée doit être supérieure à 1 et inférieure
à 100, en pratique la croissance est factorielle en mémoire donc en ne
dépassera pas 10*/
private int depth;
private Plateau plateau;
private Joueur target;
private Joueur opponent;
private int d_gen;
public AlgoRechercheMinMax(int depth, int d_gen, Joueur joueur1, Joueur joueur2){
this.depth = depth;
this.d_gen = d_gen;
//Cet algo ne marche qu'avec des jeux à deux joueurs
target = joueur1;
opponent = joueur2;
}
public void setRandGenDepth(int d_gen){
this.d_gen = d_gen;
}
public void setDepth(int depth){
this.depth = depth;
}
public void setPlayers(Joueur joueur1, Joueur joueur2){
target = joueur1;
opponent = joueur2;
}
public int getRandGenDepth(int d_gen){
return d_gen;
}
public int getDepth(int depth){
return depth;
}
public Joueur[] getPlayers(Joueur joueur1, Joueur joueur2){
Joueur[] players = {target, opponent};
return players;
}
public Coup meilleurCoup( Plateau _plateau , Joueur _joueur , boolean _ponder ){
plateau = _plateau;
plateau.sauvegardePosition(0);
if(target != _joueur){
opponent = target;
target = _joueur;
}
ArbreMinMax explore = new ArbreMinMax();
builder(explore, target, 0);
}
//Fonction auxiliaire récursive de création de l'arbre des coups possibles
private void builder(ArbreMinMax t,Joueur currentJoueur, int currentDepth){
//On commence par mettre le plateau à jour en fonction du coup théorique joué
if(currentDepth == 0){
plateau.restaurePosition(0);
}
else{
plateau.restaurePosition(currentDepth-1);
plateau.joueCoup(t.getcoup());
plateau.sauvegardePosition(currentDepth);
}
//On crée les nouveau noeuds à partir des coups disponible du point de vue du joueur à ce niveau de l'arbre
ArrayList<Coup> coups = plateau.getListeCoups(currentJoueur);
//On part du principe que la partie n'est pas terminée donc qu'il reste au moins un coup
if(coups.size()==1){
plateau.joueCoup(coups.get(0));
ArrayList<ArbreMinMax> fils = new ArrayList<ArbreMinMax>();
ArbreMinMax a = new ArbreMinMax(coups.get(0));
Joueur winner = plateau.vainqueur();
if(winner == target){
a.setvalue(1);
}
else if(winner == opponent){
a.setvalue(-1);
}
else {
a.setvalue(0);
}
fils.add(a);
t.setfils(fils);
}
else if (currentDepth == depth - 1){
ArrayList<ArbreMinMax> fils = new ArrayList<ArbreMinMax>();
for(int i=0; i<coups.size();i++){
plateau.joueCoup(coups.get(i));
ArbreMinMax a = new ArbreMinMax(coups.get(i));
int c = Generator.random_tests(plateau, d_gen, target);
a.setvalue(c);
fils.add(a);
plateau.annuleDernierCoup();
}
t.setfils(fils);
}
else{
ArrayList<ArbreMinMax> fils = new ArrayList<ArbreMinMax>();
for(int i=0; i<coups.size();i++){
ArbreMinMax a = new ArbreMinMax(coups.get(i));
if(currentJoueur == target){
builder(a, opponent,currentDepth + 1);
}
else {
builder(a, target,currentDepth + 1);
}
fils.add(a);
}
t.setfils(fils);
}
}
}
...@@ -15,6 +15,8 @@ import static tictactoecodingame.Generator.random_tests; ...@@ -15,6 +15,8 @@ import static tictactoecodingame.Generator.random_tests;
public class ArbreMinMax { public class ArbreMinMax {
protected int value; protected int value;
//Coup théorique joué à ce noeud
protected Coup coup;
protected ArrayList<Coup> coups; protected ArrayList<Coup> coups;
protected ArrayList<ArbreMinMax> fils; protected ArrayList<ArbreMinMax> fils;
...@@ -23,6 +25,10 @@ public class ArbreMinMax { ...@@ -23,6 +25,10 @@ public class ArbreMinMax {
public ArbreMinMax(){ public ArbreMinMax(){
} }
public ArbreMinMax(Coup coup){
this.coup = coup;
}
public ArbreMinMax(int value, ArrayList coups, ArrayList fils){ public ArbreMinMax(int value, ArrayList coups, ArrayList fils){
this.value = value; this.value = value;
this.fils = fils; this.fils = fils;
...@@ -61,6 +67,10 @@ public class ArbreMinMax { ...@@ -61,6 +67,10 @@ public class ArbreMinMax {
} }
} }
public Coup getcoup(){
return coup;
}
public ArrayList getcoups(){ public ArrayList getcoups(){
return(coups); return(coups);
} }
......
...@@ -10,7 +10,7 @@ package tictactoecodingame; ...@@ -10,7 +10,7 @@ package tictactoecodingame;
* @author Théo * @author Théo
*/ */
public class Generator { public class Generator {
public static int random_tests(Plateau plateau, int nb_tests) { public static int random_tests(Plateau plateau, int nb_tests,Joueur target) {
int c = 0; int c = 0;
JoueurOrdi player = new JoueurOrdi("player"); JoueurOrdi player = new JoueurOrdi("player");
JoueurOrdi opponent = new JoueurOrdi("oppo"); JoueurOrdi opponent = new JoueurOrdi("oppo");
...@@ -39,9 +39,9 @@ public class Generator { ...@@ -39,9 +39,9 @@ public class Generator {
} }
Joueur vainqueur = plateau.vainqueur(); Joueur vainqueur = plateau.vainqueur();
if ( vainqueur == player ) if ( vainqueur.getIdJoueur() == target.getIdJoueur() )
c++; c++;
else if ( vainqueur == player ) else if ( vainqueur.getIdJoueur() != target.getIdJoueur() )
c--; c--;
plateau.restaurePosition(0); plateau.restaurePosition(0);
} }
......
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