diff --git a/window.cpp b/window.cpp index f5310a8ed7577c89b3b293fab1dbc37f53df1c6b..a35cca87da2b733e895fe29e0d1447859ad435bf 100644 --- a/window.cpp +++ b/window.cpp @@ -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 (cell.collapsed) + continue; + else if (cell.possibleStates < minEtropy) { - if (grid[x + y * 9].collapsed) - continue; - else if (grid[x + y * 9].possibleStates < minEtropy) - { - minEtropy = grid[x + y * 9].possibleStates; - b.clear(); - b.push_back(&grid[x + y * 9]); - } - else if (grid[x + y * 9].possibleStates == minEtropy) - { - b.push_back(&grid[x + y * 9]); - } + minEtropy = cell.possibleStates; + b.clear(); + b.push_back(&cell); + } + else if (cell.possibleStates == minEtropy) + { + b.push_back(&cell); } } if (b.size() == 0) // if b is empty -> solved - { - qInfo("Solved!!"); return; - } + else if (minEtropy == 0) { qInfo("backtracking");