From 503e6f2184fbce66373f47b04e0ca4f657e0c4ad Mon Sep 17 00:00:00 2001 From: Silas Dohm <silas.dohm@stud.hs-bochum.de> Date: Wed, 3 Aug 2022 14:29:14 +0200 Subject: [PATCH] clear sodoku button added, renamed vars --- window.cpp | 27 +++++++++++++++++++-------- window.h | 5 +++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/window.cpp b/window.cpp index f78ca48..f633621 100644 --- a/window.cpp +++ b/window.cpp @@ -10,14 +10,18 @@ Window::Window(QWidget *parent) : QWidget{parent} { setFixedWidth(1600); - m_button = new QPushButton("solve", this); - connect(m_button, SIGNAL(clicked()), this, SLOT(solveButtonClicked())); - m_button->setGeometry(1200, height() - 30, width() - 1200, 30); + m_solveButton = new QPushButton("solve", this); + m_solveButton->setGeometry(1100, height() - 100, width() - 1200, 30); + connect(m_solveButton, SIGNAL(clicked()), this, SLOT(solveButtonClicked())); + m_clearButton = new QPushButton("Clear",this); + m_clearButton->setGeometry(1100, height() - 30, width() - 1200, 30); + connect(m_clearButton,SIGNAL(clicked()),this,SLOT(clearButtonClicked())); + m_slider = new QSlider(this); m_slider->setRange(0, 1000); m_slider->setOrientation(Qt::Horizontal); m_slider->setValue(m_delay); - m_slider->setGeometry(1200, height() - 60, width() - 1200, 30); + m_slider->setGeometry(1100, height() - 60, width() - 1200, 30); connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); int dx = 0; @@ -72,11 +76,11 @@ Window::Window(QWidget *parent) void Window::solveButtonClicked() { std::list<History *> hist; - bool end = false; + bool backtracking = false; srand(time(NULL)); while (1) { - if (end) + if (backtracking) { hist.back()->cell->un(); if (hist.back()->index.size() == 0) @@ -84,7 +88,7 @@ void Window::solveButtonClicked() hist.pop_back(); continue; } - end = false; + backtracking = false; int choiceNr = rand() % hist.back()->index.size(); // choose a random number; hist.back()->cell->collapse(hist.back()->index[choiceNr]); // collapse cell with chosen number; std::vector<int>::iterator it; @@ -121,7 +125,7 @@ void Window::solveButtonClicked() else if (minEtropy == 0) { qInfo("backtracking"); - end = true; + backtracking = true; continue; } @@ -136,6 +140,13 @@ void Window::solveButtonClicked() // qInfo("%d---:)"); } +void Window::clearButtonClicked(){ + for(auto& x: m_cell){ + if(x.collapsed) + x.un(); + } + return; +} void Window::setValue(int s) { m_delay = s; diff --git a/window.h b/window.h index e0adef7..0f240a1 100644 --- a/window.h +++ b/window.h @@ -13,8 +13,8 @@ public: explicit Window(QWidget *parent = nullptr); private: - QPushButton *m_buttonQuit; - QPushButton *m_button; + QPushButton *m_clearButton; + QPushButton *m_solveButton; QPushButton *grid[9][9]; QProgressBar *m_progressBar; QSlider *m_slider; @@ -40,6 +40,7 @@ signals: private slots: void setValue(int s); void solveButtonClicked(); + void clearButtonClicked(); }; #endif // WINDOW_H -- GitLab