BUT39Octobre/Nim/MinMax.java
2024-10-09 12:32:16 +02:00

47 lines
949 B
Java

package Nim;
import fr.iut_fbleau.raw_api_body.entity.Plateau;
import fr.iut_fbleau.raw_api_body.entity.Ply;
import java.util.Iterator;
public class MinMax {
public static int ExploreMin(Plateau plateau){
int min = 1;
int temp;
if (plateau.isFinished()){
return plateau.getResult();
}
Iterator<Ply> plies = plateau.givePlies();
for (Iterator<Ply> it = plies; it.hasNext(); ) {
Ply ply = it.next();
plateau.doPly(ply);
temp = ExploreMax(plateau);
if (temp < min) min = temp;
plateau.undoPly(ply);
}
return min;
}
public static int ExploreMax(Plateau plateau){
int max = -1;
int temp;
if (plateau.isFinished()){
return plateau.getResult();
}
Iterator<Ply> plies = plateau.givePlies();
for (Iterator<Ply> it = plies; it.hasNext(); ) {
Ply ply = it.next();
plateau.doPly(ply);
temp = ExploreMin(plateau);
if (temp > max) max = temp;
plateau.undoPly(ply);
}
return max;
}
}