Example #1
0
        //CONSTRUCTEUR

        public CGrille(int ligneLengthInt, int colonneLengthInt)
        {
            m_ligneLengthInt   = ligneLengthInt;
            m_colonneLengthInt = colonneLengthInt;

            // IL faut créer maintenant une grille où l'on retrouve dans chaque case de la grille, une cellule
            //Initialisation de la grille avec création de cellule à chaque "case"

            //On a donc
            m_grille = new CCellule[ligneLengthInt, colonneLengthInt];

            //Ensuite on donne une valeur a chacune des cellules (NB que le remplissage aléatoire est créer après)

            for (int i = 0; i < ligneLengthInt; i++)
            {
                for (int j = 0; j < colonneLengthInt; j++)
                {
                    m_grille[i, j] = new CCellule(i, j, false);
                }
            }

            RemplissageGrilleAleatoire(50);


            //  RemplissageGrille_PourTest();
            // On doit maintenant écrire la méthode pour pouvoir afficher la grille correctement
        }
Example #2
0
        // Méthode pour déterminer l'état N + 1 d'une cellule

        #region Evolution de la grille tour par tour en fonction des voisins adjacents

        public void EvolutionDeLaGrille(CCellule mycell)
        {
            CCellule returnedCellule = new CCellule();
            int      i = mycell.PLigneInt;
            int      j = mycell.PColonneInt;

            // Survie : de la cellule avec 2 ou 3 voisins Vivants
            // Si la cellule est vivante ...
            if (((NombresVoisinsAdjacentsInt(mycell) == 2) || (NombresVoisinsAdjacentsInt(mycell) == 3)) && (mycell.EtatCelluleBool))
            {
                Console.WriteLine("Je passe ici 1");
                Console.WriteLine("Avant avoir fait l'intruction voici l'état de m_grille : <" + m_grille[i, j].toString() + ">");

                returnedCellule = m_grille[i, j];// ... on la laisse vivante
                Console.WriteLine("Après avoir fait l'intruction voici l'état de m_grille : <" + m_grille[i, j].toString() + ">");
                Console.WriteLine("Après avoir fait l'intruction voici l'état de returnedCellule : <" + returnedCellule.toString() + ">");
            }

            // Mort : 4 ou plus voisins OU moins d'un 1 voisin
            else if ((NombresVoisinsAdjacentsInt(mycell) > 4) || (NombresVoisinsAdjacentsInt(mycell) == 1) || (NombresVoisinsAdjacentsInt(mycell) == 0) || (NombresVoisinsAdjacentsInt(mycell) == 4))
            {
                Console.WriteLine("Je passe ici 2");
                Console.WriteLine("Avant avoir fait l'intruction voici l'état de m_grille: <" + m_grille[i, j].toString() + ">");

                returnedCellule = m_grille[i, j];// ... on fait mourrir la cellule
                returnedCellule.ChangementEtatToFalse();
                Console.WriteLine("après avoir fait l'intruction voici l'état de m_grille : <" + m_grille[i, j].toString() + ">");

                Console.WriteLine("Après avoir fait l'intruction voici l'état de returnedCellule : <" + returnedCellule.toString() + ">");
            }

            // Naissance : Pour une case vide, 3 voisins vivants
            else if ((!mycell.EtatCelluleBool) && (NombresVoisinsAdjacentsInt(mycell) == 3))
            {
                Console.WriteLine("Je passe ici 3");
                Console.WriteLine("Avant avoir fait l'intruction voici l'état de m_grille: <" + m_grille[i, j].toString() + ">");

                returnedCellule = m_grille[i, j];// ... on crée une nouvelle cellule
                returnedCellule.ChangementEtatToTrue();
                Console.WriteLine("Après avoir fait l'intruction voici l'état de m_grille : <" + m_grille[i, j].toString() + ">");

                Console.WriteLine("Après avoir fait l'intruction voici l'état de returnedCellule : <" + returnedCellule.toString() + ">");
            }

            else
            {
                throw new Exception("ERREUR : <(" + mycell.toString() + ")> n'est pas passée dans les conditions");
            }
        }
Example #3
0
        public CCellule GetCellule(int i, int j)
        {
            CCellule returnedCellule = new CCellule();

            if ((i >= 0 && i < m_ligneLengthInt) && (j >= 0 && j < m_colonneLengthInt))
            {
                returnedCellule.Clone(m_grille[i, j]);
            }
            else
            {
                throw new Exception("La cellule <(" + i + "," + j + ")> n'existe pas");
            }


            return(returnedCellule);
        }
Example #4
0
 public void RemplissageGrille_PourTest()
 {
     for (int i = 0; i < m_ligneLengthInt; i++)
     {
         for (int j = 0; j < m_colonneLengthInt; j++)
         {
             if (j % 2 == 0)
             {
                 m_grille[i, j] = new CCellule(i, j, true);
             }
             else
             {
                 m_grille[i, j] = new CCellule(i, j, false);
             }
         }
     }
 }
Example #5
0
 public void CloneMort(CCellule mycell)
 {
     m_pLigneInt       = mycell.PLigneInt;
     m_pColonneInt     = mycell.PColonneInt;
     m_etatCelluleBool = !EtatCelluleBool;
 }
Example #6
0
        public int NombresVoisinsAdjacentsInt(CCellule mycell)
        {
            int i = mycell.PLigneInt;
            int j = mycell.PColonneInt;
            int voisinsVivantsInt = 0;

            //int ligneEnCoursInt = int.MinValue;
            // int colonneEnCoursInt = int.MinValue;


            if (i != 0 && j != 0 & i != m_ligneLengthInt - 1 && j != m_colonneLengthInt - 1)
            {
                //ON GERE LES CAS DES CELLULES QUI NE SONT PAS AUX FRONTIERES (cf torique)
                if (m_grille[i - 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            #region Controle des adjacences pour les 4 coins de la grille
            else if (i == 0 && j == 0)
            {
                // Pour l'angle en haut à gauche
                if (m_grille[m_ligneLengthInt - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }

            else if (i == 0 && j == m_colonneLengthInt - 1)
            {
                // Pour l'angle en haut à droite
                if (m_grille[0, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            else if (i == m_ligneLengthInt - 1 && j == 0)
            {
                // Pour l'angle en bas à gauche
                if (m_grille[m_ligneLengthInt - 1, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1 - 1, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1 - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1 - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            else if (i == m_ligneLengthInt - 1 && j == m_colonneLengthInt - 1)
            {
                // Pour l'angle en bas à droite
                if (m_grille[m_ligneLengthInt - 1 - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1 - 1, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, m_colonneLengthInt - 1 - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1 - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            #endregion

            #region Controle des adjacences pour les frontières de la grille
            else if (i == 0)
            {
                // Controle pour la ligne supérieure ( i = 0)
                if (m_grille[m_ligneLengthInt - 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[m_ligneLengthInt - 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            else if (i == m_ligneLengthInt - 1)
            {
                // Controle sur la frontière en bas
                if (m_grille[i - 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[0, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }

            else if (j == 0)
            {
                if (m_grille[i - 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, m_colonneLengthInt - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j + 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }

            else if (j == m_colonneLengthInt - 1)
            {
                if (m_grille[i - 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i - 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j - 1].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, j].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
                if (m_grille[i + 1, 0].EtatCelluleBool)
                {
                    voisinsVivantsInt++;
                }
            }
            #endregion


            else
            {
                throw new Exception("i et j non gérés ");
            }

            return(voisinsVivantsInt);
        }