public override int Jouer(PositionS p, bool asj1) { sw.Restart(); Func <int, float, float> phi = (C, W) => (a + W) / (a + C); racine = new NoeudS(null, p); iter = 0; while (sw.ElapsedMilliseconds < temps) { NoeudS no = racine; do // Sélection { no.CalculMeilleurFils(phi, gen); no = no.MeilleurFils(); } while (no.cross > 0 && no.fils.Length > 0); float re = JeuHasard(no.p); // Simulation while (no != null) // Rétropropagation { no.cross += 1; no.win += re; no = no.pere; } iter++; } racine.CalculMeilleurFils(phi, gen); int rep = (asj1) ? racine.indiceMeilleurFils1 : racine.indiceMeilleurFils0; return(rep); }
public override int Jouer(PositionS p, bool asj1) { sw.Restart(); Func <int, float, float> phi = (W, C) => (a + W) / (a + C); racine = new NoeudS(null, p); int iter = 0; int totale_re; while (sw.ElapsedMilliseconds < temps) { this.TaskList = new List <Task <int> >(); totale_re = 0; NoeudS no = racine; do // Sélection { no.CalculMeilleurFils(phi, gen[N - 1]); no = no.MeilleurFils(); } while (no.cross > 0 && no.fils.Length > 0); for (int i = 0; i < this.N; i++)//simulation { int j = i; TaskList.Add(Task.Run(() => JeuHasard(no.p, j))); } Task.WaitAll(TaskList.ToArray()); for (int i = 0; i < TaskList.Count; i++) { totale_re += TaskList[i].Result; } while (no != null) // Rétropropagation { no.cross += this.N * 2; no.win += totale_re; no = no.pere; } iter++; } racine.CalculMeilleurFils(phi, gen[N - 1]); int rep = (asj1) ? racine.indiceMeilleurFils1 : racine.indiceMeilleurFils0; return(rep); }