Commit dd141a58 authored by MACE Lloyd's avatar MACE Lloyd

Replace Util.java

parent 96fdf0b8
/*
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mcts;
import java.util.ArrayList;
import tictactoecodingame.Coup;
import tictactoecodingame.GrilleTicTacToe3x3;
import tictactoecodingame.Joueur;
import tictactoecodingame.Plateau;
/**
*
......@@ -17,83 +14,27 @@ import tictactoecodingame.Plateau;
*/
public class Util {
public static Coup getMeilleurCoup(Noeud racine, Joueur joueur) {
ArrayList<Coup> listeCoupsRacine = racine.getEtat().getPlateau().getListeCoups(joueur);
/*System.out.println(getMeilleurNoeud(racine)==null);
System.out.println(getMeilleurNoeud(racine).getEtat().getPlateau()==null);
System.out.println(getMeilleurNoeud(racine).getEtat().getPlateau().getListeCoups(joueur)==null);*/
if (listeCoupsRacine.size() == 1) {
return listeCoupsRacine.get(0);
}
else {
ArrayList<Coup> listeCoupsEnfant = getMeilleurNoeud(racine).getEtat().getPlateau().getListeCoups(joueur);
for (int i=0; i<listeCoupsRacine.size() - 1; i++) {
/*
System.out.println(listeCoupsRacine);
System.out.println(listeCoupsEnfant);
System.out.println(test);
System.out.println(listeCoupsEnfant.get(i));
*/
if (!listeCoupsRacine.get(i).equals(listeCoupsEnfant.get(i))) {
return listeCoupsRacine.get(i);
}
}
return listeCoupsRacine.get(listeCoupsRacine.size() - 1);
}
}
public static Noeud getMeilleurNoeud(Noeud racine) {
Noeud meilleurNoeud = null;
public static Coup getMeilleurCoup(Noeud racine) {
Noeud meilleurNoeud = new Noeud();
double score;
double meilleurScore = Integer.MIN_VALUE;
for (Noeud enfant : racine.getListeEnfant()) {
score = enfant.getEtat().getNbVictoire() / enfant.getEtat().getNbVisite();
score = (double) enfant.getEtat().getNbVictoire() / (double) enfant.getEtat().getNbVisite();
if (score > meilleurScore) {
meilleurScore = score;
meilleurNoeud = enfant;
}
}
return meilleurNoeud;
return meilleurNoeud.getEtat().getDernierCoup();
}
public static Plateau copyPlateau(Plateau plateau) {
Plateau nouveauPlateau = new GrilleTicTacToe3x3();
for (int i = 0; i <plateau.getNbLignes(); i++) {
for (int j = 0; j <plateau.getNbColonnes(); j++) {
if (nouveauPlateau.getGrille()[i][j] != plateau.getGrille()[i][j]) {
nouveauPlateau.getGrille()[i][j] = plateau.getGrille()[i][j];
}
public static Joueur swapJoueur(Joueur currentJoueur, Joueur joueur1, Joueur joueur2) {
if (currentJoueur == joueur1) {
currentJoueur = joueur2;
} else {
currentJoueur = joueur1;
}
}
return nouveauPlateau;
}
public static ArrayList<Coup> copyCoupsPossibles(Noeud noeud, Joueur joueur) {
ArrayList<Coup> coupsPossibles = new ArrayList();
for (Coup coup : noeud.getEtat().getPlateau().getListeCoups(joueur)) {
coupsPossibles.add(coup);
}
return coupsPossibles;
}
public static Joueur getAdversaire(Joueur joueur) {
joueur.setIdJoueur(1-joueur.getIdJoueur());
return joueur;
}
public static void setAdversaire(Joueur joueur) {
joueur.setIdJoueur(1-joueur.getIdJoueur());
}
public static int getNumAdversaire(int numJoueur) {
return 1 - numJoueur;
}
public static void setNumAdversaire(int numJoueur) {
numJoueur = 1 - numJoueur;
}
return currentJoueur;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment