Ejemplo n.º 1
0
        public static int[,] RunAutomataTimestep(int[,] grid, int[] born, int[] survive)
        {
            var newgrid   = new int[grid.GetLength(0), grid.GetLength(1)];
            var neighbors = CellularAutomata.Convolve(grid, FeatureFilters.NeighborCount);

            Debug.WriteLine(neighbors.Total());
            for (int x = 0; x < grid.GetLength(0); x++)
            {
                for (int y = 0; y < grid.GetLength(1); y++)
                {
                    if (grid[x, y] == 1 && survive.Contains(neighbors[x, y]))
                    {
                        newgrid[x, y] = 1;
                    }
                    else if (grid[x, y] == 0 && born.Contains(neighbors[x, y]))
                    {
                        newgrid[x, y] = 1;
                    }
                    else
                    {
                        newgrid[x, y] = 0;
                    }
                }
            }
            return(newgrid);
        }
        public void ConvoleTest()
        {
            var grid   = CellularAutomata.RandomFill(10, 15);
            var conv   = CellularAutomata.Convolve(grid, FeatureFilters.Identity);
            var gTotal = grid.Total();
            var cTotal = conv.Total();

            Assert.AreEqual(gTotal, cTotal);
        }