Esempio n. 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;

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

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


                int re = JeuHasard(no.p); // Simulation

                while (no != null)        // Rétropropagation
                {
                    no.cross += 2;
                    no.win   += re;
                    no        = no.pere;
                }
                iter++;
            }
            racine.CalculMeilleurFils(phi);
            Console.WriteLine("{0} itérations", iter);
            Console.WriteLine(racine);
            return(racine.indiceMeilleurFils);
        }
Esempio n. 2
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);
        }