Esempio n. 1
0
        public void NextGeneration()
        {
            var modifiedCells = new List <Tuple <Tuple <int, int>, CellState> >();

            for (var row = 0; row < ActiveGeneration.Rows; row++)
            {
                for (var column = 0; column < ActiveGeneration.Columns; column++)
                {
                    var cell       = ActiveGeneration.GetCell(row, column);
                    var neighbours = GetNumberOfCellNeighbours(cell, ActiveGeneration);

                    if (cell.State == CellState.Alive && (neighbours < UnderpopulationRule || neighbours > OverpopulationRule))
                    {
                        modifiedCells.Add(new Tuple <Tuple <int, int>, CellState>(cell.Position, CellState.Dead));
                    }
                    else if ((cell.State == CellState.Dead || cell.State == CellState.Empty) && neighbours == ReproductionRule)
                    {
                        modifiedCells.Add(new Tuple <Tuple <int, int>, CellState>(cell.Position, CellState.Alive));
                    }
                }
            }

            if (modifiedCells.Any())
            {
                GenerationNumber++;

                Parallel.ForEach(modifiedCells,
                                 tuple => ActiveGeneration.SetCell(tuple.Item1.Item1, tuple.Item1.Item2, tuple.Item2));
            }
        }
Esempio n. 2
0
 public Cell GetCell(int row, int column)
 {
     return(ActiveGeneration.GetCell(row, column));
 }
Esempio n. 3
0
 public void Reset()
 {
     GenerationNumber = 1;
     ActiveGeneration.Reset();
 }
Esempio n. 4
0
 public void UpdateCellState(int row, int column)
 {
     ActiveGeneration.UpdateCellState(row, column);
 }
Esempio n. 5
0
 public void SetCell(int row, int column, CellState state)
 {
     ActiveGeneration.SetCell(row, column, state);
 }