Пример #1
0
        private static InfiniteGrid3D RunCycle(InfiniteGrid3D grid, bool useFourthDimension)
        {
            var gridClone = new InfiniteGrid3D(grid);

            var minBounds = grid.GetMinBounds();

            minBounds.X--;
            minBounds.Y--;
            minBounds.Z--;

            var maxBounds = grid.GetMaxBounds();

            maxBounds.X++;
            maxBounds.Y++;
            maxBounds.Z++;

            if (useFourthDimension)
            {
                minBounds.W--;
                maxBounds.W++;
            }

            for (int w = (int)minBounds.W; w <= (int)maxBounds.W; w++)
            {
                for (int z = (int)minBounds.Z; z <= (int)maxBounds.Z; z++)
                {
                    for (int y = (int)minBounds.Y; y <= (int)maxBounds.Y; y++)
                    {
                        for (int x = (int)minBounds.X; x <= (int)maxBounds.X; x++)
                        {
                            int numberOfActiveNeighbours = GetNumberOfActiveNeighbours(grid, x, y, z, w, useFourthDimension);

                            var cubeState = grid.GetPoint(x, y, z, w);

                            if (cubeState == CubeState.Active && (numberOfActiveNeighbours < 2 || numberOfActiveNeighbours > 3))
                            {
                                gridClone.SetPoint(x, y, z, w, CubeState.Inactive);
                            }
                            else if (cubeState == CubeState.Inactive && numberOfActiveNeighbours == 3)
                            {
                                gridClone.SetPoint(x, y, z, w, CubeState.Active);
                            }
                        }
                    }

                    PrintGrid(gridClone, z, w);
                }
            }

            return(gridClone);
        }
Пример #2
0
        private static void PrintGrid(InfiniteGrid3D grid, int z, int w)
        {
            Logger.Debug($"z={z}, w={w}");

            var minBounds = grid.GetMinBounds();
            var maxBounds = grid.GetMaxBounds();

            for (int y = (int)minBounds.Y; y <= (int)maxBounds.Y; y++)
            {
                string line = string.Empty;

                for (int x = (int)minBounds.X; x <= (int)maxBounds.X; x++)
                {
                    line += grid.GetPoint(x, y, z, w) == CubeState.Active ? "#" : ".";
                }

                Logger.Debug(line);
            }

            Logger.Debug(string.Empty);
        }