Exemplo n.º 1
0
        //Constructeur de PositionTron avec un autre PositionTron
        public PositionTron(PositionTron p)
        {

            this.plateau = new int[nbL + 2, nbC + 2];
            for (int i = 0; i < nbL + 2; i++)
            {
                for (int j = 0; j < nbC + 2; j++)
                {
                    if (i == 0 || i == (nbL + 1) || j == 0 || j == (nbC + 1))
                    {
                        plateau[i, j] = 8;
                    }
                }
            }
            this.pJ1 = new int[2] { p.pJ1[0], p.pJ1[1] };
            this.pJ0 = new int[2] { p.pJ0[0], p.pJ0[1] };
            this.pJ1D = new int[2] { p.pJ1D[0], p.pJ1D[1] };
            this.pJ0D = new int[2] { p.pJ0D[0], p.pJ0D[1] };
            plateau[pJ1[0], pJ1[1]] = 1;
            plateau[pJ0[0], pJ0[1]] = 2;
            Eval = p.Eval;
            NbCoups1 = p.NbCoups1;
            NbCoups0 = p.NbCoups0;
            direc1 = p.direc1;
            direc0 = p.direc0;
        }
Exemplo n.º 2
0
        public override bool Equals(Object obj)
        {
            if ((obj == null) || !this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }
            PositionTron position = (PositionTron)obj;
            bool         equal    = ((this.NbCoups1 == position.NbCoups1) && (this.Eval == position.Eval)) || (this.NbCoups0 == position.NbCoups0) && (this.Eval == position.Eval);

            for (int i = 0; i < nbL; i++)
            {
                for (int j = 0; j < nbC; j++)
                {
                    if (this.plateau[i, j] != position.plateau[i, j])
                    {
                        equal = false;
                        break;
                    }
                }
                if (!equal)
                {
                    break;
                }
            }
            return(equal);
        }
Exemplo n.º 3
0
        public override int Jouer(PositionS p, bool asj1)
        { //Re-ecrire méthode Jouer
            PositionTron pT = (PositionTron)p;
            int choix1 = 0;
            int choix0 = 0; ;
            string c = "";
            if (asj1 == true)
            {
                Console.WriteLine("Vous avez " + pT.NbCoups1 + " coups possibles à choisir." + "Vous pouvez choisir entre 0 et " + (pT.NbCoups1 - 1) + ".");
                Console.WriteLine("sens comme dessous:");
                if (pT.direc1[0, 0] == -1) { Console.WriteLine("Vous pouvez bouger vers le haut"); }
                if (pT.direc1[1, 1] == -1) { Console.WriteLine("Vous pouvez bouger à gauche"); }
                if (pT.direc1[2, 1] == 1) { Console.WriteLine("Vous pouvez bouger à droit"); }
                if (pT.direc1[3, 0] == 1) { Console.WriteLine("Vous pouvez bouger vers le bas"); }
                Console.WriteLine("Joueur 1, entrez votre choix !");
                c = Console.ReadLine();
                while (!Int32.TryParse(c, out choix1) || choix1 > pT.NbCoups1 - 1)
                {
                    Console.WriteLine("Erreur Input!!!entrez votre choix correcte!!!");
                    c = Console.ReadLine();
                    Int32.TryParse(c, out choix1);
                }
            }
            else if (asj1 == false)
            {
                Console.WriteLine("Vous avez " + pT.NbCoups0 + " coups possibles à choisir." + "Vous pouvez choisir entre 0 et " + (pT.NbCoups0 - 1) + ".");
                Console.WriteLine("sens comme dessous:");
                if (pT.direc0[0, 0] == -1)
                {
                    Console.WriteLine("Vous pouvez bougez vers le haut");
                }
                if (pT.direc0[1, 1] == -1)
                {
                    Console.WriteLine("Vous pouvez bougez vers  à gauche");
                }
                if (pT.direc0[2, 1] == 1)
                {
                    Console.WriteLine("Vous pouvez bougez vers à droit");
                }
                if (pT.direc0[3, 0] == 1)
                {
                    Console.WriteLine("Vous pouvez bougez le bas");
                }
                Console.WriteLine("Joueur 0, donnez votre choix !");
                c = Console.ReadLine();
                while (!Int32.TryParse(c, out choix0) || choix1 > pT.NbCoups0 - 1)
                {
                    Console.WriteLine("Erreur Input!!!entrez votre choix correcte!!!");
                    c = Console.ReadLine();
                    Int32.TryParse(c, out choix0);
                }
            }
            return asj1 ? choix1 : choix0;

        }
Exemplo n.º 4
0
    static void Championnat(int nombre_joueurs)
    {
        int N = nombre_joueurs;

        JMCTSS[] joueurs = new JMCTSS[N];
        for (int i = 0; i < N; i++)
        {
            joueurs[i] = new JMCTSS(i + 1, 100);
        }
        PositionTron position;
        PartieS      partie;

        int[]     victoires = new int[N];
        Stopwatch watch     = new Stopwatch();

        watch.Start();
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (i != j)
                {
                    position = new PositionTron(1, 1, 3, 3);
                    partie   = new PartieS(joueurs[i], joueurs[j], position);
                    partie.Commencer(false);
                    if (partie.r < 0)
                    {
                        victoires[j]++;
                    }
                    if (partie.r > 0)
                    {
                        victoires[i]++;
                    }
                }
            }
            Console.Write($"{i} ");
        }
        watch.Stop();
        Console.WriteLine();
        Console.WriteLine("Time elapsed: {0}", watch.Elapsed);
        for (int i = 0; i < N; i++)
        {
            Console.WriteLine($"Parametre a = {i + 1}, nombre de victoires: {victoires[i]}.");
        }
    }
Exemplo n.º 5
0
    static void VersusTron(string Joueur1 = "Humain", string Joueur0 = "JMCTSS", int NbParties = 4)
    {
        int     a1       = 22;
        int     a2       = 22;
        int     temps    = 100;
        int     NbThread = 2;
        JoueurS j1;
        JoueurS j0;

        switch (Joueur1)
        {
        case "JMCTSS":
            j1 = new JMCTSS(a1, temps);
            break;

        case "JMCTSSp":
            j1 = new JMCTSSp(a1, temps, NbThread);
            break;

        default:
            j1 = new JoueurHumainTron();
            break;
        }
        switch (Joueur0)
        {
        case "Humain":
            j0 = new JoueurHumainTron();
            break;

        case "JMCTSSp":
            j0 = new JMCTSSp(a2, temps, NbThread);
            break;

        default:
            j0 = new JMCTSS(a2, temps);
            break;
        }
        PositionTron p;
        PartieS      partie;
        int          score_j1 = 0;
        int          score_j0 = 0;
        bool         start    = true;

        Console.WriteLine("Score : (J1 - J0)");
        for (int i = 0; i < NbParties; i++)
        {
            p      = new PositionTron(1, 2, 3, 4);
            partie = new PartieS(j1, j0, p);
            partie.Commencer(true);

            if (partie.r < 0)
            {
                score_j1++;
            }
            else if (partie.r > 0)
            {
                score_j0++;
            }
            start = !start;
            Console.WriteLine($"{score_j1} - {score_j0}");
        }
        Console.WriteLine($"Joueur1 : {Joueur1}({a1},{temps}) VS Joueur0 : {Joueur0}({a2},{temps}) sur {NbParties} Parties, " +
                          $"avec nombre de Thread {NbThread}.");
        Console.WriteLine($"Le joueur1 a gagné {score_j1} parties.");
        Console.WriteLine($"Le joueur0 a gagné {score_j0} parties.");
    }