c'est le désespoir
This commit is contained in:
@@ -3,6 +3,7 @@ package fr.iut_fbleau.HexGame;
|
||||
import fr.iut_fbleau.GameAPI.*;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class Simulation extends AbstractGame {
|
||||
@@ -27,16 +28,18 @@ public class Simulation extends AbstractGame {
|
||||
|
||||
//METHODES
|
||||
/*Le jeu de Hex ne peut jamais finir avec le résultat null. En utilisant cette propriété, on peut avoir cet algorithme simplifié du monte-carlo*/
|
||||
private float MonteCarlo(HexBoard position){
|
||||
RandomBot simplay = new RandomBot();
|
||||
private float MonteCarlo(HexBoard position, Player current){
|
||||
RandomBot simplay = new RandomBot(current, new Random().nextLong());
|
||||
HexBoard simpos = position;
|
||||
LinkedList<Integer[]> ctaken = taken;
|
||||
HexPly testmove;
|
||||
float wins = 0;
|
||||
float losses = 0;
|
||||
int count = 0;
|
||||
|
||||
for(int i=0; i<EVALDEPTH; i++){
|
||||
while(!simpos.isGameOver()){
|
||||
count++;
|
||||
testmove = (HexPly) simplay.giveYourMove(simpos);
|
||||
if(!ctaken.contains(new Integer[]{testmove.getRow(), testmove.getCol()}) && simpos.isLegal(testmove)){
|
||||
ctaken.add(new Integer[]{testmove.getRow(), testmove.getCol()});
|
||||
@@ -48,15 +51,18 @@ public class Simulation extends AbstractGame {
|
||||
}
|
||||
}
|
||||
}
|
||||
simpos = position;
|
||||
//System.out.println("count:"+count);
|
||||
for (int j=0; j<count; j++) {
|
||||
simpos.undoPly();
|
||||
}
|
||||
ctaken = taken;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if(wins>=losses){
|
||||
return losses/wins;
|
||||
} else {
|
||||
return -(wins/losses);
|
||||
}
|
||||
System.out.println(" wins : "+wins+"/losses : "+losses);
|
||||
System.out.println(" eval : "+(wins-losses)/EVALDEPTH);
|
||||
|
||||
return (wins-losses)/EVALDEPTH;
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +72,7 @@ public class Simulation extends AbstractGame {
|
||||
} else if (position.getResult()==Result.WIN){
|
||||
return 1.0f;
|
||||
} else if (depth==MAXDEPTH) {
|
||||
return MonteCarlo(position);
|
||||
return MonteCarlo(position, Player.PLAYER1);
|
||||
} else {
|
||||
float bestcase = -1.0f;
|
||||
HexPly bestcasemove;
|
||||
@@ -108,7 +114,7 @@ public class Simulation extends AbstractGame {
|
||||
} else if (position.getResult()==Result.WIN){
|
||||
return 1.0f;
|
||||
} else if (depth==MAXDEPTH) {
|
||||
return MonteCarlo(position);
|
||||
return MonteCarlo(position, Player.PLAYER2);
|
||||
} else {
|
||||
float bestcase = 1.0f;
|
||||
HexPly bestcasemove;
|
||||
@@ -150,7 +156,7 @@ public class Simulation extends AbstractGame {
|
||||
} else if (position.getResult()==Result.WIN){
|
||||
return 1.0f;
|
||||
} else if (depth==MAXDEPTH) {
|
||||
return MonteCarlo(position);
|
||||
return MonteCarlo(position, Player.PLAYER1);
|
||||
} else {
|
||||
float bestcase = A;
|
||||
HexPly bestcasemove;
|
||||
@@ -194,7 +200,7 @@ public class Simulation extends AbstractGame {
|
||||
} else if (position.getResult()==Result.WIN){
|
||||
return 1.0f;
|
||||
} else if (depth==MAXDEPTH) {
|
||||
return MonteCarlo(position);
|
||||
return MonteCarlo(position, Player.PLAYER2);
|
||||
} else {
|
||||
float bestcase = B;
|
||||
HexPly bestcasemove;
|
||||
|
||||
Reference in New Issue
Block a user