Exemplo n.º 1
0
        public void Initialize(int cellsCount)
        {
            for (int index = 0; index < cellsCount; index++)
            {
                int rowIndex    = rnd.Next(1, field.RowsCount + 1);
                int columnIndex = rnd.Next(1, field.ColumnsCount + 1);

                field.Spawn(rowIndex, columnIndex);
            }
        }
Exemplo n.º 2
0
        public void DoStep()
        {
            CellAutomataField newField = new CellAutomataField(field.RowsCount, field.ColumnsCount);

            for (int rowIndex = 1; rowIndex < field.RowsCount - 1; rowIndex++)
            {
                for (int colIndex = 1; colIndex < field.ColumnsCount - 1; colIndex++)
                {
                    if (field.Get(rowIndex, colIndex) == 1 && strategy.HasSurvived(getNeighborsPattern(rowIndex, colIndex)))
                    {
                        newField.Spawn(rowIndex, colIndex);
                    }
                    else if (field.Get(rowIndex, colIndex) == 0 && strategy.HasBorn(getNeighborsPattern(rowIndex, colIndex)))
                    {
                        newField.Spawn(rowIndex, colIndex);
                    }
                }
            }

            field = newField;
        }