本文整理汇总了C++中Sudoku::getField方法的典型用法代码示例。如果您正苦于以下问题:C++ Sudoku::getField方法的具体用法?C++ Sudoku::getField怎么用?C++ Sudoku::getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sudoku
的用法示例。
在下文中一共展示了Sudoku::getField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solve
void RecursiveSolver::solve(Sudoku& sudoku) {
this->_field = sudoku.getField();
options = findMissing();
for(map<int,vector<int>>::iterator it = options.begin(); it != options.end(); ++it) {
cout << it->first << " " << ": ";
for (vector<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
cout << *it2 << ", ";
}
cout << endl;
}
map<int,vector<int>>::iterator it = options.begin();
count = 0;
int status = -1;
do {
status = guess(it->first);
switch(status) {
case RETURN_NEXT:
it = std::next(it);
break;
case RETURN_PREV:
it = std::prev(it);
break;
}
} while(status != RETURN_EXIT);
sudoku.setField(_field);
}
示例2: solve
void Solver::solve(Sudoku& sudoku) {
this->_field = sudoku.getField();
if (_field.countEmpty() == 0) {
cout << "RETURN SOLVE BECAUSE NO EMPTY SLOTS 1" << endl;
return;
}
// Look for slots with only one option, fill it in and repeat
bool hit;
do {
hit = false;
// Find all possible options for the empty slots
missing = findMissing();
// Find all slots with only one option
for (int index = 0; index < _field.getSizeSq(); ++index) {
if (missing[index].size() == 1) {
_field.set(index, missing[index].at(0));
missing[index].clear();
cout << "MADE A HIT AT " << index << " WITH " << _field.get(index) << endl;
hit = true;
}
}
} while (hit == true);
// We completed the puzzle, thus return
if (_field.countEmpty(true) == 0) {
cout << "RETURN SOLVE BECAUSE NO EMPTY SLOTS 2" << endl;
sudoku.setField(_field);
return;
}
// No more sure slots, so start guessing
std::cout << "COMPLETED ALL SURE HITS, START GUESSING" << std::endl;
// Print the result so far
std::cout << "RESULT SO FAR: " << std::endl;
Sudoku s = Sudoku();
s.setField(_field);
s.print();
// Find all possible options for the remaining empty slots
missing = findMissing();
// Print all options
for (int index = 0; index < _field.getSizeSq(); ++index) {
cout << "[" << index << "]: ";
for (int index2 = 0; index2 < missing[index].size(); ++index2) {
cout << missing[index].at(index2) << " ";
}
cout << "\n";
}
emptySlots.clear();
// Fill in the empty slots to the array
for(map<int,vector<int>>::iterator it = missing.begin(); it != missing.end(); ++it) {
if ((it->second).size() > 0)
emptySlots.push_back(it->first);
}
// Sort the emptyslot indices by size small->big
std::sort(emptySlots.begin(), emptySlots.end(), lessThan);
guess(emptySlots.at(0));
sudoku.setField(_field);
}