From 70825399fd98b5784973670f8c5dc2df979aa243 Mon Sep 17 00:00:00 2001 From: Silas Dohm <silas.dohm@stud.hs-bochum.de> Date: Wed, 17 Aug 2022 17:38:46 +0200 Subject: [PATCH] moved history to stack --- window.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/window.cpp b/window.cpp index 516e8bb..4c93417 100644 --- a/window.cpp +++ b/window.cpp @@ -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; } } -- GitLab