Example #1
0
        public static Grid3D Simulate3D(Grid3D inGrid)
        {
            var outGrid = new Grid3D();

            var((xMin, xMax), (yMin, yMax), (zMin, zMax)) = inGrid.GetDimensions();
            for (var x = xMin - 1; x <= xMax + 1; x++)
            {
                for (var y = yMin - 1; y <= yMax + 1; y++)
                {
                    for (var z = zMin - 1; z <= zMax + 1; z++)
                    {
                        var neighborsCount = GetNeighborsCount3D(inGrid, x, y, z);
                        if (inGrid.IsCubeActive(x, y, z))
                        {
                            if (neighborsCount == 2 || neighborsCount == 3)
                            {
                                outGrid.SetCubeActive(x, y, z);
                            }
                        }
                        else
                        {
                            if (neighborsCount == 3)
                            {
                                outGrid.SetCubeActive(x, y, z);
                            }
                        }
                    }
                }
            }
            return(outGrid);
        }