From 96205403612c73f4c4a3247d7d96560d3d8f92e8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 10 Apr 2013 19:18:03 +0000 Subject: during the reset phase, mark cells without valid solutions as invalid() --- src/sudoku.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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); + } } } } -- cgit v1.2.3