Beispiel #1
0
        public void Evolve()
        {
            CellsNeighborhood cellsNeighborhood = new CellsNeighborhood();

            CopyCurrentStateToPreviousStates();

            foreach (var evolvingCell in PreviousState)
            {
                if (IsCellBoundary(evolvingCell))
                {
                    cellsNeighborhood = GetCellsNeighborhoodForNotBoundaryCell(evolvingCell);
                }
                else
                {
                    switch (BoundaryCondition)
                    {
                    case BoundaryConditionModel.Absorbing:
                        cellsNeighborhood = GetCellsNeighborhoodForFalseOutsideBc(evolvingCell);
                        break;

                    case BoundaryConditionModel.CounterAbsorbing:
                        cellsNeighborhood = GetCellsNeighborhoodForTrueOutsideBc(evolvingCell);
                        break;

                    case BoundaryConditionModel.Periodic:
                        cellsNeighborhood = GetCellsNeighborhoodForPeriodicalBc(evolvingCell);
                        break;
                    }
                }

                CurrentState[evolvingCell.Id].IsAlive = Rule.Table[cellsNeighborhood];
            }

            GenerationCount++;
        }
Beispiel #2
0
        private CellsNeighborhood GetCellsNeighborhoodForPeriodicalBc(CellModel cell)
        {
            CellsNeighborhood cellsNeighborhood = new CellsNeighborhood();

            if (cell.Id == FirstCellId)
            {
                cellsNeighborhood.Left   = PreviousState[LastCellId].IsAlive;
                cellsNeighborhood.Center = PreviousState[cell.Id].IsAlive;
                cellsNeighborhood.Right  = PreviousState[cell.Id + 1].IsAlive;
            }

            if (cell.Id == LastCellId)
            {
                cellsNeighborhood.Left   = PreviousState[cell.Id - 1].IsAlive;
                cellsNeighborhood.Center = PreviousState[cell.Id].IsAlive;
                cellsNeighborhood.Right  = PreviousState[FirstCellId].IsAlive;
            }

            return(cellsNeighborhood);
        }
Beispiel #3
0
        private CellsNeighborhood GetCellsNeighborhoodForTrueOrFalseOutsideBc(CellModel cell, bool isOutsideAlive)
        {
            CellsNeighborhood cellsNeighborhood = new CellsNeighborhood();

            if (cell.Id == FirstCellId)
            {
                cellsNeighborhood.Left   = isOutsideAlive;
                cellsNeighborhood.Center = PreviousState[cell.Id].IsAlive;
                cellsNeighborhood.Right  = PreviousState[cell.Id + 1].IsAlive;
            }

            if (cell.Id == LastCellId)
            {
                cellsNeighborhood.Left   = PreviousState[cell.Id - 1].IsAlive;
                cellsNeighborhood.Center = PreviousState[cell.Id].IsAlive;
                cellsNeighborhood.Right  = isOutsideAlive;
            }

            return(cellsNeighborhood);
        }