42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
public class MinimaxProfondeur {
|
|
|
|
// Minimax avec profondeur fixe
|
|
public static int PROFONDEUR_MAX = 4;
|
|
|
|
public static int exploreMax(int n, int profondeur) {
|
|
if (n <= 0) return -1;
|
|
if (profondeur == 0) return evaluer(n);
|
|
|
|
int meilleur = Integer.MIN_VALUE;
|
|
for (int coups = 1; coups <= 3; coups++) {
|
|
int res = exploreMin(n - coups, profondeur - 1);
|
|
meilleur = Math.max(meilleur, res);
|
|
}
|
|
return meilleur;
|
|
}
|
|
|
|
public static int exploreMin(int n, int profondeur) {
|
|
if (n <= 0) return +1;
|
|
if (profondeur == 0) return evaluer(n);
|
|
|
|
int pire = Integer.MAX_VALUE;
|
|
for (int coups = 1; coups <= 3; coups++) {
|
|
int res = exploreMax(n - coups, profondeur - 1);
|
|
pire = Math.min(pire, res);
|
|
}
|
|
return pire;
|
|
}
|
|
|
|
// Fonction hsimple : perdant si n % 4 == 0
|
|
public static int evaluer(int n) {
|
|
return (n % 4 == 0) ? -1 : +1;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
int n = 8;
|
|
int profondeur = PROFONDEUR_MAX;
|
|
int resultat = exploreMax(n, profondeur);
|
|
System.out.println("Résultat (profondeur fixe) pour n=" + n + " → " + resultat);
|
|
}
|
|
}
|