Selection.java 1.43 KB
Newer Older
Louis Bahrman's avatar
Louis Bahrman committed
1 2 3 4 5 6 7
/*
 * 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 tictactoecodingame;

8 9
import java.util.ArrayList;

Louis Bahrman's avatar
Louis Bahrman committed
10 11 12 13 14
/**
 *
 * @author louis
 */
public class Selection {
15 16 17 18 19 20 21 22 23 24 25
    ArrayList<Integer> chemin;
    
    public Selection(){
        chemin=new ArrayList<>();
    }
    
    
    public Selection(double c, ArbreMCTS a){
        Selection s=new Selection();
        chemin=SelectionAux(c, a, s, 0).chemin;
    }
Louis Bahrman's avatar
Louis Bahrman committed
26
    
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    private Selection SelectionAux(double c, ArbreMCTS a, Selection s, int nbSimulPere){
        if (a.estFeuille()){
            return s;
        }
        else {
            double coefMax=0;
            int indiceSelection=0;
            ArrayList<ArbreMCTS> f=a.getfils();
            for(int i=0;i<f.size();i++){
                ArbreMCTS arbreTeste = f.get(i);
                double coef =arbreTeste.getvalue()+c*Math.sqrt(Math.log(nbSimulPere)/arbreTeste.getFraction().getDenominateur());
                if (coef>coefMax){
                    indiceSelection=i;
                    coefMax=coef;
                }
            }
            ArbreMCTS arbreSelectionne=f.get(indiceSelection);
            int nbSimulPereNew=arbreSelectionne.getFraction().getDenominateur();
            s.chemin.add(indiceSelection);
            return SelectionAux(c,arbreSelectionne,s,nbSimulPereNew);
47
        }       
Louis Bahrman's avatar
Louis Bahrman committed
48 49
    }
}