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

clear sodoku button added, renamed vars

parent 4fff46bf
Branches
No related tags found
1 merge request!2backtracking
......@@ -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;
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment