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

moved history to stack

parent 77f31348
Branches
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ Window::Window(QWidget *parent)
void Window::solveButtonClicked()
{
std::list<History *> hist;
std::list<History> hist;
bool backtracking = false;
srand(time(NULL)); // random seed
while (1)
......@@ -89,20 +89,20 @@ void Window::solveButtonClicked()
delay(m_delay);
if (backtracking)
{
hist.back()->cell->un();
if (hist.back()->index.size() == 0)
hist.back().cell->un();
if (hist.back().index.size() == 0)
{
hist.pop_back();
continue;
}
backtracking = false;
int choiceNr = rand() % hist.back()->index.size(); // choose a random number;
int choiceNr = rand() % hist.back().index.size(); // choose a random number;
repaint(); // draw cells again
delay(m_delay);
hist.back()->cell->collapse(hist.back()->index[choiceNr]); // collapse cell with chosen number;
hist.back().cell->collapse(hist.back().index[choiceNr]); // collapse cell with chosen number;
std::vector<int>::iterator it;
it = hist.back()->index.begin() + choiceNr;
hist.back()->index.erase(it);
it = hist.back().index.begin() + choiceNr;
hist.back().index.erase(it);
}
else
{
......@@ -140,7 +140,7 @@ void Window::solveButtonClicked()
int choiceCell = rand() % b.size(); // choose a random cell
int choiceNr = rand() % b[choiceCell]->index.size(); // choose a random number;
hist.push_back(new History(b[choiceCell], b[choiceCell]->index, choiceNr));
hist.push_back(History(b[choiceCell], b[choiceCell]->index, choiceNr));
b[choiceCell]->collapse(b[choiceCell]->index[choiceNr]); // collapse that random cell with chosen number;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment