LETSGOOOOOOO
This commit is contained in:
11
Nim/MainNim.java
Normal file
11
Nim/MainNim.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package Nim;
|
||||
|
||||
import fr.iut_fbleau.raw_api_body.entity.Plateau;
|
||||
|
||||
public class MainNim {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Plateau p = new PlateauNim(6);
|
||||
System.out.println(MinMax.ExploreMax(p));
|
||||
}
|
||||
}
|
||||
46
Nim/MinMax.java
Normal file
46
Nim/MinMax.java
Normal file
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class PlateauNim implements Plateau {
|
||||
|
||||
public PlateauNim(int allumette) {
|
||||
this.allumette = allumette;
|
||||
this.currrentPlayer = currrentPlayer.JOUEUR1;
|
||||
this.currrentPlayer = Player.JOUEUR1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,9 +21,9 @@ public class PlateauNim implements Plateau {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
public int getResult() {
|
||||
if (isFinished()) {
|
||||
if (currrentPlayer == JOUEUR1) {
|
||||
if (currrentPlayer == Player.JOUEUR1) {
|
||||
return Result.GAGNE;
|
||||
} else {
|
||||
return Result.PERDU;
|
||||
@@ -51,6 +51,28 @@ public class PlateauNim implements Plateau {
|
||||
return plies.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPly(Ply ply) {
|
||||
PlyNim plynim = (PlyNim) ply;
|
||||
allumette -= plynim.coup;
|
||||
if (currrentPlayer == Player.JOUEUR1){
|
||||
currrentPlayer = Player.JOUEUR2;
|
||||
} else {
|
||||
currrentPlayer = Player.JOUEUR1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoPly(Ply ply) {
|
||||
PlyNim plynim = (PlyNim) ply;
|
||||
allumette += plynim.coup;
|
||||
if (currrentPlayer == Player.JOUEUR1){
|
||||
currrentPlayer = Player.JOUEUR2;
|
||||
} else {
|
||||
currrentPlayer = Player.JOUEUR1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
if (allumette == 0) {
|
||||
@@ -60,16 +82,5 @@ public class PlateauNim implements Plateau {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doo(Ply arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'doo'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(Ply arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'undo'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user