Пример #1
0
        public void StepLife()
        {
            var NewLife = new List <LifeCell>();

            var surroundcheck = new LifeSurround(Now, Rule);

            foreach (var cell in Now.AliveCells)
            {
                var surroundings = surroundcheck.GetPotential(cell);

                foreach (var maybecell in surroundings)
                {
                    var surroundingspotential = surroundcheck.Get(maybecell);

                    if (surroundingspotential.Count() >= Rule.RuleForBirth.CountAliveCells)
                    {
                        if (NewLife.Where(x => x.Coordinate.X == maybecell.Coordinate.X && x.Coordinate.Y == maybecell.Coordinate.Y).Count() == 0)
                        {
                            NewLife.Add(maybecell);
                        }
                    }
                }
            }

            Now.AliveCells.AddRange(NewLife);
        }
Пример #2
0
        public void StepDeath()
        {
            var fordeath = new List <LifeCell>();

            var surroundcheck = new LifeSurround(Now, Rule);

            foreach (var cell in Now.AliveCells)
            {
                var surroundings = surroundcheck.Get(cell);

                if (surroundings.Count() < Rule.RuleForDeath.CountMinLifeCells ||
                    surroundings.Count() > Rule.RuleForDeath.CountMaxLifeCells)
                {
                    fordeath.Add(cell);
                }
            }

            foreach (var cell in fordeath)
            {
                Now.AliveCells.Remove(cell);
            }
        }