possibleValuesAt method
Returns the set of possible values that can be placed at the specified
position of the Board.
If the row or col is out of range, a RangeError is thrown.
Implementation
Set<int> possibleValuesAt({required int row, required int col}) {
_checkRowCol(row, col);
var possibleValues =
Set<int>.from(List.generate(Board.maxValue, (i) => i + 1));
// Removes all values already in the same row and column.
for (var i = 0; i < Board.dimension; i++) {
possibleValues.remove(_values[row][i]);
possibleValues.remove(_values[i][col]);
}
// Removes all values already in the same board section
var rowStart = (row / Board.groupSize).floor() * Board.groupSize;
var colStart = (col / Board.groupSize).floor() * Board.groupSize;
for (var i = rowStart; i < rowStart + Board.groupSize; i++) {
for (var j = colStart; j < colStart + Board.groupSize; j++) {
possibleValues.remove(_values[i][j]);
}
}
return possibleValues;
}