Commit 96fdf0b8 authored by MACE Lloyd's avatar MACE Lloyd

Class Util

parent a035b988
/*
* 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;
/**
*
* @author Lloyd
*/
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;
double score;
double meilleurScore = Integer.MIN_VALUE;
for (Noeud enfant : racine.getListeEnfant()) {
score = enfant.getEtat().getNbVictoire() / enfant.getEtat().getNbVisite();
if (score > meilleurScore) {
meilleurScore = score;
meilleurNoeud = enfant;
}
}
return meilleurNoeud;
}
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];
}
}
}
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;
}
}
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