Ejemplo n.º 1
0
        public override int Jouer(Position p)
        {
            Func <int, int, float> phi = (W, C) => (a + W) / (b + C);

            racine = null;
            int j = 0;

            while (racine == null)
            {
                if (memoire == null)
                {
                    racine = new Noeud(null, p); break;
                }
                if (memoire[j] == null)
                {
                    racine = new Noeud(null, p); break;
                }


                if (p.Equals((object)memoire[j].p))
                {
                    racine = memoire[j];
                }

                j++;
            }

            int iter = j;

            sw.Restart();

            while (sw.ElapsedMilliseconds < temps)
            {
                Noeud no = racine;

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


                Task <int>[] tblthread = new Task <int> [Nbrthreads];
                int          re        = 0;
                for (int i = 0; i < Nbrthreads; i++)
                {
                    tblthread[i] = Task.Run(() => JeuHasard(no.p));
                }
                Task.WaitAll(tblthread);
                for (int jj = 0; jj < Nbrthreads; jj++)
                {
                    re = re + tblthread[jj].Result;
                }

                // Simulation

                while (no != null) // Rétropropagation
                {
                    no.cross += 2 * Nbrthreads;
                    no.win   += re;
                    no        = no.pere;
                }

                iter++;
            }
            racine.CalculMeilleurFils(phi);
            racine.MeilleurFils().p.Affiche();
            Console.WriteLine("{0} itérations", iter);
            Console.WriteLine(racine);
            memoire = racine.fils[racine.indiceMeilleurFils].fils;
            return(racine.indiceMeilleurFils);
        }
Ejemplo n.º 2
0
 public Noeud(Noeud pere, Position p)
 {
     this.pere = pere;
     this.p    = p;
     fils      = new Noeud[this.p.NbCoups];
 }