ajout TP1 presque finis

This commit is contained in:
James Boutaric
2025-09-11 11:37:24 +02:00
parent 001ee76228
commit bf9189502a
10 changed files with 246 additions and 44 deletions

34
TP1/MinimaxStop.java Normal file
View File

@@ -0,0 +1,34 @@
public class MinimaxStop {
// Minimax avec détection de victoire immédiate
public static int exploreMax(int n) {
if (n <= 0) return -1;
int meilleur = Integer.MIN_VALUE;
for (int coups = 1; coups <= 3; coups++) {
int res = exploreMin(n - coups);
if (res == +1) return +1; // victoire immédiate
meilleur = Math.max(meilleur, res);
}
return meilleur;
}
public static int exploreMin(int n) {
if (n <= 0) return +1;
int pire = Integer.MAX_VALUE;
for (int coups = 1; coups <= 3; coups++) {
int res = exploreMax(n - coups);
if (res == -1) return -1; // défaite immédiate pour Max
pire = Math.min(pire, res);
}
return pire;
}
public static void main(String[] args) {
int n = 7;
int resultat = exploreMax(n);
System.out.println("Résultat pour n=" + n + "" + resultat);
}
}