コード例 #1
0
ファイル: Grille.cs プロジェクト: ChoucheneH/SudokuWPF
        internal bool Aunjumeau(int i, int j)
        {
            Case[,] TabCarreJumeau = new Case[(int) Math.Sqrt(size), (int) Math.Sqrt(size)];
            Case[] TabJumeauResolu = new Case[(int)Math.Sqrt(size)];

            TabCarreJumeau = CarreJumeau(i, j);
            bool EstJumeaux=false;
            if (AunJumeauLigne(TabCarreJumeau,i, j))
            {
                RésoluJumeauLigne(TabCaseJum, i, j);
                EstJumeaux = true;

            }
            else if (AunJumeauColonne(TabCarreJumeau,i, j))
            {
                RésoluJumeauColonne(TabCaseJum, i, j);
                EstJumeaux = true;
            }

            return EstJumeaux;
        }
コード例 #2
0
ファイル: Grille.cs プロジェクト: ChoucheneH/SudokuWPF
        private void RésoluJumeauLigne(Case[] TabJumeau, int i, int j)
        {
            char x1 = TabJumeau[0].Hypotheses[0];
            char x2 = TabJumeau[0].Hypotheses[1];
            char y1 = TabJumeau[1].Hypotheses[0];
            char y2 = TabJumeau[1].Hypotheses[1];
            //MessageBox.Show("Ligne : "+i + " - " + j);
            int tailleCarré = (int)Math.Sqrt(size);
            if (x1 == y1)
            {
                TraiterLigne(i, j, x1, tailleCarré);
            }
            else if (x1 == y2)
            {
                TraiterLigne(i, j, x1, tailleCarré);
            }
            else if (x2 == y1)
            {
                TraiterLigne(i, j, x2, tailleCarré);
            }
            else if (x2 == y2)
            {
                TraiterLigne(i, j, x2, tailleCarré);

            }
        }
コード例 #3
0
ファイル: Grille.cs プロジェクト: ChoucheneH/SudokuWPF
        private void CréerLesCases(char[,] Tab)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {

                    if (Symbole.IndexOf(Tab[i, j]) != -1)
                    {
                        nbHypothese = 1;
                        Hypotheses = new char[nbHypothese];
                        Hypotheses[0] = Tab[i, j];

                        tabCase[i, j] = new Case(Tab[i, j], nbHypothese, Hypotheses);
                    }
                    else
                    {
                        //MessageBox.Show("Il manque qlq fonctionnalité au Grille.cs");

                        InitialiserTabVérifNombre();
                        nbHypothese = size;
                        RechercheParLigne(Tab[i, j], i, j);

                        RechercheParColonne(Tab[i, j], i, j);

                        RechercheParRegion(Tab[i, j], i, j);

                        Hypotheses = new char[nbHypothese];

                        int compte = 0;

                        for (int p = 0; p < size; p++)
                        {
                            if (!tabVérifNombre[p])
                            {
                                Hypotheses[compte] = Symbole[p];
                                compte++;

                            }

                        }

                        tabCase[i, j] = new Case(Tab[i, j], nbHypothese, Hypotheses);

                    }
                }
            }
        }
コード例 #4
0
ファイル: Grille.cs プロジェクト: ChoucheneH/SudokuWPF
        private Case[,] CarreJumeau(int lig, int col)
        {
            int tailleCarré = (int)Math.Sqrt(size);
            int divC, divL, modC, modL;
            Case[,] tab = new Case[tailleCarré, tailleCarré];

            divC = col / tailleCarré;
            modC = col % tailleCarré;
            divL = lig / tailleCarré;
            modL = lig % tailleCarré;
            int x = 0;
            for (int i = divL * tailleCarré; i < divL * tailleCarré + tailleCarré; i++)
            {
                int y = 0;
                for (int j = divC * tailleCarré; j < divC * tailleCarré + tailleCarré; j++)
                {

                    tab[x, y] = TabCase[i, j];
                    y++;
                }
                x++;
            }
            return tab;
        }
コード例 #5
0
ファイル: Grille.cs プロジェクト: ChoucheneH/SudokuWPF
        private bool AunJumeauLigne(Case[,] TabCarreJumeau, int lig, int col)
        {
            int tailleCarré = (int)Math.Sqrt(size);
            Case[] tabjum = new Case[tailleCarré];
            bool CarréEstValide = false;
            int divC, divL, modC, modL;

            divC = col / tailleCarré;
            modC = col % tailleCarré;
            divL = lig / tailleCarré;
            modL = lig % tailleCarré;
            int compte = 0;
            for (int i = 0; i < tailleCarré; i++)
            {
                if (TabCarreJumeau[modL, i].NbHypothese == 2)
                {
                    tabjum[compte] = TabCarreJumeau[modL, i];
                    compte++;
                }

            }
            if (compte == 2)
            {
                TabCaseJum = tabjum;
                CarréEstValide = true;
            }

            return CarréEstValide;
        }
コード例 #6
0
ファイル: Grille.cs プロジェクト: AurelienVialon/ProjetSMA
        public Grille(int h, int l, int nbA, int nbB, int nbAgents, double kp, double km, int p, double vit)
        {
            kplus   = kp;
            kmoins  = km;
            vitesse = vit;
            map     = new Case[l][];
            pas     = p;
            for (int j = 0; j < l; j++)
            {
                this.ColumnDefinitions.Add(new ColumnDefinition());
                map[j] = new Case[h];
            }
            for (int i = 0; i < h; i++)
            {
                this.RowDefinitions.Add(new RowDefinition());
            }
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    Case c = new Case();
                    map[j][i] = c;
                    Children.Add(c);
                    Grid.SetColumn(c, j);
                    Grid.SetRow(c, i);
                }
            }
            try
            {
                for (int i = 0; i < nbA; i++)
                {
                    Random r = new Random();
                    int?   x = null;
                    int?   y = null;
                    do
                    {
                        x = r.Next() % l;
                        y = r.Next() % h;
                    } while (map[(int)x][(int)y].contenu != null);
                    map[(int)x][(int)y].contenu = new Objet("A");
                }
            }
            catch (Exception e)
            {
            }
            for (int i = 0; i < nbB; i++)
            {
                Random r = new Random();
                int?   x = null;
                int?   y = null;
                do
                {
                    x = r.Next() % l;
                    y = r.Next() % h;
                } while (map[(int)x][(int)y].contenu != null);
                map[(int)x][(int)y].contenu = new Objet("B");
            }

            for (int i = 0; i < nbAgents; i++)
            {
                int?x = null;
                int?y = null;
                do
                {
                    x = r.Next() % l;
                    y = r.Next() % h;
                } while (map[(int)x][(int)y].contenu != null);
                Agent a = new Agent((int)x, (int)y);
                map[(int)x][(int)y].contenu = a;
                a.Run();
            }
        }