public NoeudP MeilleurFils(int j) { if (fils[indiceMeilleurFils[j]] != null) { return(fils[indiceMeilleurFils[j]]); } Position q = p.Clone(); q.EffectuerCoup(indiceMeilleurFils[j]); fils[indiceMeilleurFils[j]] = new NoeudP(this, q, this.N); return(fils[indiceMeilleurFils[j]]); }
public NoeudP(NoeudP pere, Position p, int nb_thread) { this.pere = pere; this.p = p; this.fils = new NoeudP[this.p.NbCoups]; this.N = nb_thread; this.win = new int[nb_thread]; this.cross = new int[nb_thread]; for (int i = 0; i < N; i++) { this.win[i] = 0; this.cross[i] = 0; } this.indiceMeilleurFils = new int[nb_thread]; }
public override int Jouer(Position p) { sw.Restart(); Func <int, int, float> phi = (W, C) => (a + W) / (b + C); racine = new NoeudP(null, p, this.N); if (racine == null) { racine = new NoeudP(null, p, this.N); } else { racine = racine.MeilleurFils(0); for (int i = 0; i < racine.p.NbCoups; i++) { if ((racine.fils[i] != null) && (racine.fils[i].p.Equals(p))) { racine = racine.fils[i]; break; } } } int iter = 0; while (sw.ElapsedMilliseconds < temps) { this.TaskList = new List <Task>(); NoeudP no = racine; for (int i = 0; i < this.N; i++) { int j = i; this.TaskList.Add(Task.Run(() => Calcul(no, phi, j))); iter++; } Task.WaitAll(this.TaskList.ToArray()); } Console.WriteLine("{0} itérations", iter); Console.WriteLine(racine); racine.CalculMeilleurFils(phi); return(racine.indiceMeilleurFils[0]); }
public void Calcul(NoeudP no, Func <int, int, float> phi, int i) { do // Sélection { no.CalculMeilleurFils(phi); no = no.MeilleurFils(i); } while (no.cross[i] > 0 && no.fils.Length > 0); re[i] = JeuHasard(no.p, i); // Simulation while (no != null) // Rétropropagation { no.cross[i] += 2; no.win[i] += re[i]; no = no.pere; } Console.WriteLine("test"); }
public override void NouvellePartie() { this.racine = null; }