예제 #1
0
        public CellularAutomaton(Config config)
        {
            this.config = config;
            cells       = new CellState[config.width, config.height];
            copy        = new CellState[config.width, config.height];

            visitAliveBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy.IsInBounds(neighbourX, neighbourY))
                {
                    if (copy[neighbourX, neighbourY] == CellState.Alive)
                    {
                        aliveNeighbours++;
                    }
                }
                else
                {
                    aliveNeighbours++;
                }
            };
            visitDeadBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy[neighbourX, neighbourY] == CellState.Alive)
                {
                    aliveNeighbours++;
                }
            };

            FillWithNoise(config.startNoise);
        }
        private int CountAliveNeighbourCells(CellState[,] grid, int x, int y)
        {
            int count = 0;

            if (aliveBorders)
            {
                grid.VisitMooreNeighbours(x, y, false, (neighbourX, neighbourY) =>
                {
                    if (grid.IsInBounds(neighbourX, neighbourY))
                    {
                        if (grid[neighbourX, neighbourY] == CellState.Alive)
                        {
                            count++;
                        }
                    }
                    else
                    {
                        count++;
                    }
                });
            }
            else
            {
                grid.VisitMooreNeighbours(x, y, true, (neighbourX, neighbourY) =>
                {
                    if (grid[neighbourX, neighbourY] == CellState.Alive)
                    {
                        count++;
                    }
                });
            }
            return(count);
        }
        public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders)
        {
            this.width        = width;
            this.height       = height;
            this.ruleset      = ruleset;
            this.aliveBorders = aliveBorders;
            cells             = new CellState[width, height];
            copy = new CellState[width, height];

            visitAliveBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy.IsInBounds(neighbourX, neighbourY))
                {
                    if (copy[neighbourX, neighbourY] == CellState.Alive)
                    {
                        aliveNeighbours++;
                    }
                }
                else
                {
                    aliveNeighbours++;
                }
            };
            visitDeadBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy[neighbourX, neighbourY] == CellState.Alive)
                {
                    aliveNeighbours++;
                }
            };

            FillWithNoise(startNoise);
        }
예제 #4
0
        public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders)
        {
            this.width = width;
            this.height = height;
            this.ruleset = ruleset;
            this.aliveBorders = aliveBorders;
            cells = new CellState[width, height];
            copy = new CellState[width, height];

            visitAliveBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy.IsInBounds(neighbourX, neighbourY))
                {
                    if (copy[neighbourX, neighbourY] == CellState.Alive)
                    {
                        aliveNeighbours++;
                    }
                }
                else
                {
                    aliveNeighbours++;
                }
            };
            visitDeadBorders = (int neighbourX, int neighbourY) =>
            {
                if (copy[neighbourX, neighbourY] == CellState.Alive)
                {
                    aliveNeighbours++;
                }
            };

            FillWithNoise(startNoise);
        }