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

removed redundant connections between cells, added repaint and sleep to...

removed redundant connections between cells, added repaint and sleep to backtracking for visualisation
parent 94ce3eb0
No related branches found
No related tags found
1 merge request!2backtracking
...@@ -58,6 +58,8 @@ Window::Window(QWidget *parent) ...@@ -58,6 +58,8 @@ Window::Window(QWidget *parent)
{ {
for (int y1 = b; y1 < b + 3; y1++) for (int y1 = b; y1 < b + 3; y1++)
{ {
if(x1 == x || y1 == y)
continue;
connect(&m_cell[x + y * 9], SIGNAL(update(int)), &m_cell[x1 + y1 * 9], SLOT(removeOption(int))); connect(&m_cell[x + y * 9], SIGNAL(update(int)), &m_cell[x1 + y1 * 9], SLOT(removeOption(int)));
connect(&m_cell[x + y * 9], SIGNAL(undo(int)), &m_cell[x1 + y1 * 9], SLOT(addOption(int))); connect(&m_cell[x + y * 9], SIGNAL(undo(int)), &m_cell[x1 + y1 * 9], SLOT(addOption(int)));
...@@ -74,6 +76,8 @@ void Window::solveButtonClicked() ...@@ -74,6 +76,8 @@ void Window::solveButtonClicked()
srand(time(NULL)); //random seed srand(time(NULL)); //random seed
while (1) while (1)
{ {
repaint(); // draw cells again
QThread::msleep(m_delay);
if (backtracking) if (backtracking)
{ {
hist.back()->cell->un(); hist.back()->cell->un();
...@@ -84,6 +88,8 @@ void Window::solveButtonClicked() ...@@ -84,6 +88,8 @@ void Window::solveButtonClicked()
} }
backtracking = false; 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
QThread::msleep(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; std::vector<int>::iterator it;
it = hist.back()->index.begin() + choiceNr; it = hist.back()->index.begin() + choiceNr;
...@@ -128,8 +134,6 @@ void Window::solveButtonClicked() ...@@ -128,8 +134,6 @@ void Window::solveButtonClicked()
hist.push_back(new History(b[choiceCell], b[choiceCell]->index, choiceNr)); hist.push_back(new History(b[choiceCell], b[choiceCell]->index, choiceNr));
b[choiceCell]->collapse(b[choiceCell]->index[choiceNr]); // collapse that random cell with chosen number; b[choiceCell]->collapse(b[choiceCell]->index[choiceNr]); // collapse that random cell with chosen number;
} }
repaint(); // draw cells again
QThread::msleep(m_delay);
} }
// qInfo("%d---:)"); // qInfo("%d---:)");
} }
...@@ -141,7 +145,6 @@ void Window::clearButtonClicked() ...@@ -141,7 +145,6 @@ void Window::clearButtonClicked()
if (x.collapsed) if (x.collapsed)
x.un(); x.un();
} }
repaint();
return; return;
} }
void Window::setValue(int s) void Window::setValue(int s)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment