Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public NoeudS MeilleurFils()
        {
            if (fils[indiceMeilleurFils1, indiceMeilleurFils0] != null)
            {
                return(fils[indiceMeilleurFils1, indiceMeilleurFils0]);
            }
            PositionS q = p.Clone();

            q.EffectuerCoup(indiceMeilleurFils1, indiceMeilleurFils0);
            fils[indiceMeilleurFils1, indiceMeilleurFils0] = new NoeudS(this, q);
            return(fils[indiceMeilleurFils1, indiceMeilleurFils0]);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public override void NouvellePartie()
 {
     racine = null;
 }
Ejemplo n.º 5
0
 public NoeudS(NoeudS pere, PositionS p)
 {
     this.pere = pere;
     this.p    = p;
     fils      = new NoeudS[this.p.NbCoups1, this.p.NbCoups0];
 }