Exemple #1
0
        public NoeudSP MeilleurFils(int j)
        {
            if (fils[indiceMeilleurFils1[j], indiceMeilleurFils0[j]] != null)
            {
                return(fils[indiceMeilleurFils1[j], indiceMeilleurFils0[j]]);
            }
            PositionS q = p.Clone();

            q.EffectuerCoup(indiceMeilleurFils1[j], indiceMeilleurFils0[j]);
            fils[indiceMeilleurFils1[j], indiceMeilleurFils0[j]] = new NoeudSP(this, q, this.N);
            return(fils[indiceMeilleurFils1[j], indiceMeilleurFils0[j]]);
        }
Exemple #2
0
        public override int Jouer(PositionS p, bool asj1)
        {
            sw.Restart();
            Func <int, float, float> phi = (W, C) => (a + W) / (a + C);

            racine = new NoeudSP(null, p, this.N);

            if (racine == null)
            {
                racine = new NoeudSP(null, p, this.N);
            }
            else
            {
                racine = racine.MeilleurFils(0);
                for (int i = 0; i < racine.p.NbCoups1 - 1; i++)
                {
                    for (int j = 0; j < racine.p.NbCoups1 - 1; j++)
                    {
                        if ((racine.fils[i, j] != null) && (racine.fils[i, j].p.Equals(p)))
                        {
                            racine = racine.fils[i, j];
                            break;
                        }
                    }
                }
            }
            int iter = 0;

            while (sw.ElapsedMilliseconds < temps)
            {
                this.TaskList = new List <Task>();
                NoeudSP no = racine;
                for (int i = 0; i < this.N; i++)
                {
                    int j = i;
                    this.TaskList.Add(Task.Run(() => Calcul(no, phi, j)));
                    iter++;
                }

                Task.WaitAll(this.TaskList.ToArray());
            }
            Console.WriteLine("{0} itérations", iter);
            Console.WriteLine(racine);
            racine.CalculMeilleurFils(phi, gen[N - 1]);
            int rep = (asj1) ? racine.indiceMeilleurFils1[0] : racine.indiceMeilleurFils0[0];

            return(rep);
        }
Exemple #3
0
 public NoeudSP(NoeudSP pere, PositionS p, int nb_thread)
 {
     this.pere  = pere;                                          //
     this.p     = p;                                             //
     this.fils  = new NoeudSP[this.p.NbCoups1, this.p.NbCoups0]; //
     this.N     = nb_thread;
     this.win   = new int[nb_thread];
     this.cross = new int[nb_thread];
     for (int i = 0; i < N; i++)
     {
         this.win[i]   = 0;
         this.cross[i] = 0;
     }
     this.indiceMeilleurFils1 = new int[nb_thread];
     this.indiceMeilleurFils0 = new int[nb_thread];
 }
Exemple #4
0
        public void Calcul(NoeudSP no, Func <int, float, float> phi, int i)
        {
            do // Sélection
            {
                no.CalculMeilleurFils(phi, gen[N - 1]);
                no = no.MeilleurFils(i);
            } while (no.cross[i] > 0 && no.fils.Length > 0);


            re[i] = JeuHasard(no.p, i); // Simulation

            while (no != null)          // Rétropropagation
            {
                no.cross[i] += 2;       //gaile
                no.win[i]   += re[i];
                no           = no.pere;
            }
        }
Exemple #5
0
 public override void NouvellePartie()
 {
     this.racine = null;
 }