예제 #1
0
        public bool AdvanceGeneration()
        {
            GenerationId++;
            var currentGameTable = GameTable.ConvertAll(x => x.DeepCopy());

            for (int i = 0; i < Abscisse; i++)
            {
                for (int j = 0; j < Ordonnee; j++)
                {
                    Case        currentCase = currentGameTable.First(myCase => myCase.X == i && myCase.Y == j);
                    List <Case> neighbours  = GetCaseNeighbours(currentGameTable, currentCase);

                    if (currentCase.isAlive)
                    {
                        //Underpopulation
                        if (neighbours.Where(myCase => myCase.isAlive == false).Count() < 2)
                        {
                            currentCase.isAlive = false;
                        }
                        //Next generation
                        else if (neighbours.Where(myCase => myCase.isAlive == true).Count() == 2 ||
                                 neighbours.Where(myCase => myCase.isAlive == true).Count() == 3)
                        {
                            currentCase.isAlive = true;
                        }
                        //Overpopulation
                        else if (neighbours.Where(myCase => myCase.isAlive == false).Count() > 3)
                        {
                            currentCase.isAlive = false;
                        }
                    }
                    else
                    {
                        //Reproduction
                        if (neighbours.Where(myCase => myCase.isAlive == true).Count() == 3)
                        {
                            currentCase.isAlive = true;
                        }
                    }
                }
            }

            this.GameTable = currentGameTable;

            AddToHistory(currentGameTable);

            return(CheckIfGenerationStucked(MaxHistoryCount));
        }