diff --git a/window.cpp b/window.cpp index f78ca48bfe789df621346fd74002a4dfe75f0364..f633621868714a02714bad31e58fa57868e34f73 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 e0adef72fdf7196e3862005096b0205e3bf67bf4..0f240a1174447ddab198d210ce075477c37278b8 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