예제 #1
0
    private static void DoCycle(ConwayGrid4D grid)
    {
        var comparer  = new ArrayByValueComparer();
        int nbActives = grid.PointsAndValues().Where(x => x.Value.before).Count();

        Console.WriteLine($"Actives : {nbActives}, Size: [{string.Join(",", grid.Size)}]");

        var minIndex = grid.MinKeys.Select(x => x - 1).ToArray();
        var maxIndex = grid.MaxKeys.Select(x => x + 1).ToArray();

        foreach (var point in grid.PointsAndValues(minIndex, maxIndex))
        {
            var nbActiveNeihbors = 0;
            foreach (var neighbor in grid.AreaSquareAround(point.Key, 1))
            {
                if (neighbor.Value.before && !comparer.Equals(point.Key, neighbor.Key))
                {
                    nbActiveNeihbors++;
                }
            }

            if (point.Value.before)
            {
                grid[point.Key] = (point.Value.before, nbActiveNeihbors.Between(2, 3));
            }
            else
            {
                grid[point.Key] = (point.Value.before, nbActiveNeihbors == 3);
            }
        }
    }
예제 #2
0
    private static ConwayGrid4D GenerateGrid4D(bool[,] inputGrid)
    {
        var grid = new ConwayGrid4D();

        for (int y = 0; y < inputGrid.GetLength(0); y++)
        {
            for (int x = 0; x < inputGrid.GetLength(0); x++)
            {
                grid[new int[] { y, x, 0, 0 }] = (inputGrid[x, y], inputGrid[x, y]);
            }
        }
        return(grid);
    }