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

clean up

parent a27052f7
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,8 @@ void Window::solveButtonClicked() ...@@ -85,6 +85,8 @@ void Window::solveButtonClicked()
validNrs.push_back(i); validNrs.push_back(i);
if (validNrs.size() == 0) if (validNrs.size() == 0)
{ {
if (hist.size() <= 0)
return;
hist.pop_back(); hist.pop_back();
continue; continue;
} }
...@@ -93,8 +95,6 @@ void Window::solveButtonClicked() ...@@ -93,8 +95,6 @@ void Window::solveButtonClicked()
hist.back().cell->collapse(validNrs[rndNr]); // collapse cell with chosen number; hist.back().cell->collapse(validNrs[rndNr]); // collapse cell with chosen number;
hist.back().blocked[validNrs[rndNr]]++; hist.back().blocked[validNrs[rndNr]]++;
} }
else
{
std::vector<Cell *> b; // vector of cells with least entropy std::vector<Cell *> b; // vector of cells with least entropy
int minEtropy = 10; int minEtropy = 10;
for (auto &cell : grid) for (auto &cell : grid)
...@@ -129,11 +129,10 @@ void Window::solveButtonClicked() ...@@ -129,11 +129,10 @@ void Window::solveButtonClicked()
validNrs.push_back(i); validNrs.push_back(i);
} }
int rndNr = rand() % validNrs.size(); // choose a random number; int rndNr = rand() % validNrs.size(); // choose a random number;
hist.push_back(History(b[rndCell], b[rndCell]->blocked, validNrs[rndNr])); hist.push_back(History(b[rndCell], validNrs[rndNr]));
b[rndCell]->collapse(validNrs[rndNr]); // collapse that random cell with chosen number; b[rndCell]->collapse(validNrs[rndNr]); // collapse that random cell with chosen number;
} }
} }
}
void Window::clearButtonClicked() void Window::clearButtonClicked()
{ {
for (auto &x : grid) for (auto &x : grid)
......
...@@ -26,10 +26,10 @@ private: ...@@ -26,10 +26,10 @@ private:
{ {
Cell *cell; Cell *cell;
std::array<int, 9> blocked; std::array<int, 9> blocked;
History(Cell *c, std::array<int,9> in, int choice) History(Cell *c, int choice)
{ {
cell = c; cell = c;
blocked =in; blocked = c->blocked;
blocked[choice] ++; blocked[choice] ++;
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment