本文整理汇总了C++中Sudoku::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Sudoku::set方法的具体用法?C++ Sudoku::set怎么用?C++ Sudoku::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sudoku
的用法示例。
在下文中一共展示了Sudoku::set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: block_groups
void block_groups(Sudoku &sudoku, int group_size, int row_block, int col_block)
{
HammingWeightIterator subset_iter(group_size);
int digit_subset;
// for each set of n numbers S = {k1, k2, ... kn}:
while ((digit_subset = subset_iter.next()) != -1)
{
// C(k) == set of columns containing k
// C(S) == union of C(k) over k in S
int blocks_containing = blockcells_containing_any(sudoku, row_block, col_block, digit_subset);
// if size(C(S)) == n
if (num_ones(blocks_containing) == group_size)
{
// remove all other possibilities from columns in C(S)
SetBitIndexIterator block_iter(blocks_containing);
auto end = SetBitIndexIterator::end();
for (; block_iter != end; ++block_iter)
{
int row, col;
blockunmask(mask(*block_iter), row, col);
row += row_block * 3;
col += col_block * 3;
int prev = sudoku(row, col);
sudoku.set(row, col, prev & digit_subset);
}
}
}
}
示例2: row_groups
void row_groups(Sudoku &sudoku, int group_size, int row)
{
HammingWeightIterator subset_iter(group_size);
int digit_subset;
// for each set of n numbers S = {k1, k2, ... kn}:
while ((digit_subset = subset_iter.next()) != -1)
{
// C(k) == set of columns containing k
// C(S) == union of C(k) over k in S
int cols_containing = columns_containing_any(sudoku, row, digit_subset);
// if size(C(S)) == n
if (num_ones(cols_containing) == group_size)
{
// remove all other possibilities from columns in C(S)
SetBitIndexIterator col_iter(cols_containing);
auto end = SetBitIndexIterator::end();
for (; col_iter != end; ++col_iter)
{
int prev = sudoku(row, *col_iter);
sudoku.set(row, *col_iter, prev & digit_subset);
}
}
}
}
示例3: box_row_eliminate
void box_row_eliminate(Sudoku &sudoku, int row, int box, int eliminate_mask)
{
for (int col = box * 3; col < (box + 1) * 3; ++col)
{
int cell = sudoku(row, col);
int newcell = subtract(cell, eliminate_mask);
sudoku.set(row, col, newcell);
}
}
示例4: solve
static bool solve(Sudoku & s) {
init_algorithm(s);
bool valid = r_solve(filter_sudoku);
if(valid) {
size_t i =0;
for(std::vector<int>& f : filter_sudoku) {
if(f.size()!=1)
std::cout<< "No solution found!";
s.set(f.front(), i/table_width, i%table_width); // Kordináták fel vannak cserélve!! HAHA :D
++i;
}
}
return valid;
}
示例5: only_in_row
void only_in_row(Sudoku &sudoku, int row)
{
int cols_who_contain[9];
sudoku.digit_to_column_map(row, cols_who_contain);
for (int num = 0; num < 9; ++num)
{
int cols = cols_who_contain[num];
if (1 == num_ones(cols))
{
int col = unmask(cols);
sudoku.set(row, col, mask(num));
}
}
}
示例6: only_in_block
void only_in_block(Sudoku &sudoku, int row_block, int col_block)
{
int friends_who_contain[9] = { 0 };
sudoku.digit_to_block_map(row_block, col_block, friends_who_contain);
int row_base = row_block * 3;
int col_base = col_block * 3;
for (int num = 0; num < 9; ++num)
{
int friends = friends_who_contain[num];
if (1 == num_ones(friends))
{
int row, col;
blockunmask(friends, row, col);
if (sudoku(row_base + row, col_base + col) != mask(num))
{
sudoku.set(row_base + row, col_base + col, mask(num));
}
}
}
}