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; }
public CellAutomata2D(int width, int height, IEvolutionStrategy strategy) { this.strategy = strategy; this.field = new CellAutomataField(height, width); }