Skip to content
Snippets Groups Projects
Commit adbac78b authored by Silas Dohm's avatar Silas Dohm
Browse files

refactor

parent 34877b77
No related branches found
No related tags found
No related merge requests found
......@@ -108,29 +108,24 @@ void Window::solveButtonClicked()
{
std::vector<Cell *> b; // vector of cells with least entropy
int minEtropy = 10;
for (int x = 0; x < 9; x++) // loop through all cells and fill list b --> this could be optimzed
for (auto &cell : grid)
{
for (int y = 0; y < 9; y++)
{
if (grid[x + y * 9].collapsed)
if (cell.collapsed)
continue;
else if (grid[x + y * 9].possibleStates < minEtropy)
else if (cell.possibleStates < minEtropy)
{
minEtropy = grid[x + y * 9].possibleStates;
minEtropy = cell.possibleStates;
b.clear();
b.push_back(&grid[x + y * 9]);
b.push_back(&cell);
}
else if (grid[x + y * 9].possibleStates == minEtropy)
else if (cell.possibleStates == minEtropy)
{
b.push_back(&grid[x + y * 9]);
}
b.push_back(&cell);
}
}
if (b.size() == 0) // if b is empty -> solved
{
qInfo("Solved!!");
return;
}
else if (minEtropy == 0)
{
qInfo("backtracking");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment