Пример #1
0
        public static void CerrularAutmataStep(this Grid grid, Grid referenceMatrix, Neighbourhood strategy, int x = 100)
        {
            NeighbourhoodCalculation neighbourAction = NeighbourhoodActive.MooreActivation;

            switch (strategy)
            {
            case Neighbourhood.Moore:
            {
                neighbourAction = NeighbourhoodActive.MooreActivation;
                break;
            }

            case Neighbourhood.VonNeumann:
            {
                neighbourAction = NeighbourhoodActive.VonNeumannActivation;
                break;
            }

            case Neighbourhood.MooreExtented:
            {
                neighbourAction = NeighbourhoodActive.MooreExtented;
                break;
            }
            }

            var random = new Random();

            Parallel.For(0, grid.Width, (i) => {
                Parallel.For(0, grid.Height, (j) => {
                    if (!grid.NotEmptyCells[i, j])
                    {
                        neighbourAction(grid,
                                        new Cell(i, j),
                                        referenceMatrix.Cells,
                                        strategy == Neighbourhood.MooreExtented ? random.Next(100) : 1,
                                        x);
                    }
                });
            });
        }
Пример #2
0
        public static void AddCAStep(this Matrix matrix, Matrix referenceMatrix, Neighbourhood strategy, int x = 100)
        {
            NeighbourhoodCalculation neighbourAction = NeighbourhoodActions.MooreAction;

            switch (strategy)
            {
            case Neighbourhood.Moore:
            {
                neighbourAction = NeighbourhoodActions.MooreAction;
                break;
            }

            case Neighbourhood.VonNeumann:
            {
                neighbourAction = NeighbourhoodActions.VonNeumannAction;
                break;
            }

            case Neighbourhood.ShapeControl:
            {
                neighbourAction = NeighbourhoodActions.ShapeControlAction;
                break;
            }
            }

            var random = new Random();

            Parallel.For(0, matrix.Width, (i) => {
                Parallel.For(0, matrix.Height, (j) => {
                    if (!matrix.NotEmptyCells[i, j])
                    {
                        neighbourAction(matrix,
                                        new Cell(i, j),
                                        referenceMatrix.Cells,
                                        strategy == Neighbourhood.ShapeControl ? random.Next(100) : 1,
                                        x);
                    }
                });
            });
        }