Exemple #1
0
        public void RunCycle()
        {
            HashSet <Point4d> newActivePoints = new HashSet <Point4d>();

            _Cycle++;

            foreach (var x in GetRange(-_Cycle, _StartingSize + _Cycle))
            {
                foreach (var y in GetRange(-_Cycle, _StartingSize + _Cycle))
                {
                    foreach (var z in GetRange(-_Cycle, _Cycle))
                    {
                        foreach (var w in GetRange(-_Cycle, _Cycle))
                        {
                            var point = new Point4d(x, y, z, w);
                            var surroundingActivePoints = GetSurroundingPoints(point).Count(p => ActivePoints.Contains(p));
                            if (ActivePoints.Contains(point))
                            {
                                if (surroundingActivePoints == 2 || surroundingActivePoints == 3)
                                {
                                    newActivePoints.Add(point);
                                }
                            }
                            else if (surroundingActivePoints == 3)
                            {
                                newActivePoints.Add(point);
                            }
                        }
                    }
                }
            }

            ActivePoints = newActivePoints;
        }
Exemple #2
0
 private static IEnumerable <Point4d> GetSurroundingPoints(Point4d center)
 {
     foreach (var x in GetRange(center.X - 1, center.X + 1))
     {
         foreach (var y in GetRange(center.Y - 1, center.Y + 1))
         {
             foreach (var z in GetRange(center.Z - 1, center.Z + 1))
             {
                 foreach (var w in GetRange(center.W - 1, center.W + 1))
                 {
                     if (center.X == x && center.Y == y && center.Z == z && center.W == w)
                     {
                         continue;
                     }
                     yield return(new Point4d(x, y, z, w));
                 }
             }
         }
     }
 }