Beispiel #1
0
        public override int Jouer(Position p)
        {
            sw.Restart();
            Func <int, int, float> phi = (W, C) => (a + W) / (b + C);

            if (racine == null)
            {
                racine = new Noeud(null, p);
            }
            else
            {
                racine = racine.MeilleurFils();
                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;
            int totale_re;

            while (sw.ElapsedMilliseconds < temps)
            {
                this.TaskList = new List <Task <int> >();
                totale_re     = 0;
                Noeud no = racine;

                do // Sélection
                {
                    no.CalculMeilleurFils(phi);
                    no = no.MeilleurFils();
                } while (no.cross > 0 && no.fils.Length > 0);


                for (int i = 0; i < this.N; i++)
                {
                    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);
            Console.WriteLine("{0} itérations", iter);
            Console.WriteLine(racine);
            return(racine.indiceMeilleurFils);
        }
Beispiel #2
0
 public Noeud(Noeud pere, Position p)
 {
     this.pere = pere;
     this.p    = p;
     fils      = new Noeud[this.p.NbCoups];
 }
Beispiel #3
0
 public override void NouvellePartie()
 {
     this.racine = null;
 }