diff options
author | Stijn Buys <ingar@osirion.org> | 2013-04-10 19:18:03 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-04-10 19:18:03 +0000 |
commit | 96205403612c73f4c4a3247d7d96560d3d8f92e8 (patch) | |
tree | a78f77f4e06fe129a5671eb7563a0a2a13085023 /src | |
parent | 44006abac0169346d67a6de31f6fe0793ead0a09 (diff) |
during the reset phase, mark cells without valid solutions as invalid()
Diffstat (limited to 'src')
-rw-r--r-- | src/sudoku.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/sudoku.cc b/src/sudoku.cc index 4fcfbf9..44f8365 100644 --- a/src/sudoku.cc +++ b/src/sudoku.cc @@ -115,8 +115,20 @@ void Sudoku::reset_cell(int pos_row, int pos_column) // set validity if ((cell(pos_row,pos_column).value() > 0) && (cell(pos_row,pos_column).value() <= 9)) { + if (!sudoku_cell[pos_row][pos_column].possibility(sudoku_cell[pos_row][pos_column].value() - 1)) { + // cell is invalid if the current value is not possible sudoku_cell[pos_row][pos_column].set_valid(false); + } else { + // cell is not valid if there are no possibilities + int n = 0; + for (int possible_value = 0; possible_value < 9; possible_value++) { + if (sudoku_cell[pos_row][pos_column].possibility(possible_value)) + n++; + } + if (n == 0) { + sudoku_cell[pos_row][pos_column].set_valid(false); + } } } } |