public void Reset() { // If we are handed an initial state then use it, else create a randomized matrix if (_initialState != null) { for (int x = 0; x < _columns; ++x) { for (int y = 0; y < _rows; ++y) { int state = _initialState [x, y]; _matrix [x, y] = new AutomataCell(state, state); } } } else { for (int x = 0; x < _columns; ++x) { for (int y = 0; y < _rows; ++y) { int state = _randomGenerator.Next(2); _matrix [x, y] = new AutomataCell(state, state); } } } }
public void VisitMatrix(Action <int> action) { for (int x = 0; x < _columns; ++x) { for (int y = 0; y < _rows; ++y) { AutomataCell cell = _matrix [x, y]; action(cell.State); } } }
public void VisitMatrix(AutomataCellVisitor action) { for (int x = 0; x < _columns; ++x) { for (int y = 0; y < _rows; ++y) { AutomataCell cell = _matrix [x, y]; action(x, y, cell); } } }
public int Evaluate(AutomataCell cell, int neighbors) { // Check the dead cells to see if they are born if (cell.State == 0) { if (_birthRule != null) { return(_birthRule [neighbors]); } return(0); } // Check the living cell to see if it survives. Living cells keep track of how long // they've been living. if (_sustainRule != null) { if (_sustainRule [neighbors] > 0) { return(cell.State + 1); } } return(0); }
public void SetNextCell(int x, int y, AutomataCell cell) { _nextMatrix [x, y] = cell; }
public void SetCell(int x, int y, AutomataCell cell) { _matrix [x, y] = cell; }