ajout TP3

This commit is contained in:
James Boutaric
2025-10-09 10:20:53 +02:00
parent 84f5b7d973
commit b9c926f493
60 changed files with 1425 additions and 304 deletions

View File

@@ -0,0 +1,47 @@
public class MIniMax_versionprofondeur_compteur {
public static int compteur_noeud = 0;
private static int ExploreMax(int nbr_allumettes, int profondeur){
compteur_noeud++;
if (nbr_allumettes <= 0){
return 1;
}
if (profondeur == 0){
return 0;
}
int meilleurres = -2;
for (int coup = 1; coup <= 3; coup++){
int res = ExploreMin(nbr_allumettes - coup, profondeur - coup);
if (res > meilleurres){
meilleurres = res;
}
}
return meilleurres;
}
private static int ExploreMin(int nbr_allumettes, int profondeur){
compteur_noeud++;
if (nbr_allumettes <= 0){
return -1;
}
if (profondeur == 0){
return 0;
}
int pire = 2;
for (int coup = 1; coup <= 3; coup++){
int res = ExploreMax(nbr_allumettes - coup, profondeur - coup);
if (res < pire){
pire = res;
}
}
return pire;
}
public static void main(String[] args) {
int nbr_allumettes = 5;
int profondeur = 6;
System.out.println(ExploreMax(nbr_allumettes, profondeur));
System.out.println(compteur_noeud);
}
}