void Solver::pointing_pair(const sud_list<sud_node> * occurrences, const niner & n, iter_over what, outcome& pp_outcome) { for (u i = 0; i < 9; ++i) { u candidate = i + 1; if (occurrences[i].size() == 2) { const u& row_1 = occurrences[i][0].rw; const u& row_2 = occurrences[i][1].rw; const u& col_1 = occurrences[i][0].cm; const u& col_2 = occurrences[i][1].cm; const bool same_row = row_1 == row_2; const bool same_col = col_1 == col_2; // if (row_1 == 6 && row_2 == 6 && col_1 == 3 && col_2 == 5) { // grid.print_possible_values(); // cout << "stop here"; // } if (what != SQUARES) { if (zero(row_1) == zero(row_2) && zero(col_1) == zero(col_2)) { niner sqr_n = grid.get_niner(SQUARES, square_index(row_1, col_1)); for (u index = 0; index < 9; ++index) { Cell& cell = *(sqr_n[index]); const sud_node& node = cell.node(); if ((node.rw == row_1 && node.cm == col_1) || (node.rw == row_2 && node.cm == col_2)) { continue; } rm_pointing_pair(cell, candidate, pp_outcome); if (pp_outcome == NEW_VALUE) return; } } } else if (what == SQUARES) { u zero_col = zero(col_1); u zero_row = zero(row_1); for (u index = 0; index < 9; ++index) { if (same_row || same_col) { // skip the three cells on the same row or column if ((same_row && zero(index) == zero_col) || (same_col && zero(index) == zero_row)) { continue; } Cell & cell = same_row ? grid.cell(row_1, index) : grid.cell(index, col_1); rm_pointing_pair(cell, candidate, pp_outcome); if (pp_outcome == NEW_VALUE) return; } } } } } }
inline bool check_position(unsigned int a,unsigned int b,unsigned int value) { if(row[a][value]||column[b][value]||square[square_index(a,b)][value]) return false; return true; }
inline void flag_position(unsigned int a,unsigned int b) { row[a][map[a][b]]=!row[a][map[a][b]]; column[b][map[a][b]]=!column[b][map[a][b]]; square[square_index(a,b)][map[a][b]]=!square[square_index(a,b)][map[a][b]]; }