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

aligned with other branch

parent b7af9f93
Branches main
No related tags found
No related merge requests found
......@@ -83,8 +83,7 @@ void Window::solveButtonClicked()
srand(time(NULL)); // random seed
while (1)
{
repaint(); // draw cells again
delay(delayTime);
delay();
if (backtracking)
{
hist.back().cell->collapsedCellClicked();
......@@ -94,18 +93,18 @@ void Window::solveButtonClicked()
validNrs.push_back(i);
if (validNrs.size() == 0)
{
if (hist.size() <= 0)
return;
hist.pop_back();
continue;
}
backtracking = false;
int rndNr = rand() % validNrs.size(); // choose a random number;
repaint(); // draw cells again
delay(delayTime);
delay();
hist.back().cell->collapse(validNrs[rndNr]); // collapse cell with chosen number;
hist.back().blocked[validNrs[rndNr]]++;
delay();
}
else
{
std::vector<Cell *> b; // vector of cells with least entropy
int minEtropy = 10;
for (auto &cell : grid)
......@@ -128,7 +127,6 @@ void Window::solveButtonClicked()
else if (minEtropy == 0)
{
// qInfo("backtracking");
backtracking = true;
continue;
}
......@@ -141,17 +139,19 @@ void Window::solveButtonClicked()
validNrs.push_back(i);
}
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;
}
}
}
inline void Window::delay(int millisecondsWait)
inline void Window::delay()
{
if(!delayTime)
return;
repaint();
QEventLoop loop;
QTimer t;
t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
t.start(millisecondsWait);
t.start(delayTime);
loop.exec();
}
void Window::clearButtonClicked()
......
......@@ -29,14 +29,14 @@ private:
{
Cell *cell;
std::array<int, 9> blocked;
History(Cell *c, std::array<int,9> in, int choice)
History(Cell *c, int choice)
{
cell = c;
blocked =in;
blocked = c->blocked;
blocked[choice]++;
}
};
inline void delay(int millisecondsWait);
inline void delay();
private slots:
void setValue(int s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment