public SmartPlayer(RuleSet ruleSet, Board board) : base(board) { _ruleSet = ruleSet; _grid = new Grid(board.CurrentDifficulty.Height, board.CurrentDifficulty.Width); _step = 0; StepsSinceReveal = 0; Reveals = 0; }
public bool Apply(RuleSet ruleSet) { //CellState[,] newValues = new CellState[_rows+2,_cols+2]; int _nextLayer = (_currentLayer + 1) % 2; bool halt = true; /* for (int i = 0; i <= _rows+1; i++) { newValues[i, 0] = _grid[i, 0]; newValues[i, _cols + 1] = _grid[i, _cols + 1]; } for (int i = 0; i <= _cols+1; i++) { newValues[0, i] = _grid[0, i]; newValues[_rows+ 1, i] = _grid[_rows + 1, i]; } */ for (byte r = 1; r <= _rows; r++) { for (byte c = 1; c <= _cols; c++) { var ns = GetNeighborhoodState(r, c); CellState? result = ruleSet.Get(ns); if(result.HasValue) { halt = halt && (_grid[_currentLayer, r, c].Value == result.Value.Value); _grid[_nextLayer,r, c] = result.Value; } else { ruleSet.Add(new Rule(ns, _grid[_currentLayer,r, c])); _grid[_nextLayer,r, c] = _grid[_currentLayer,r, c]; } } } _currentLayer = _nextLayer; return halt; }