From e42ed312d3f84a47e3efee7ffdd4bca3b4546e48 Mon Sep 17 00:00:00 2001
From: Silas Dohm <silas.dohm@stud.hs-bochum.de>
Date: Fri, 5 Aug 2022 16:43:29 +0200
Subject: [PATCH] removed redundant connections between cells, added repaint
 and sleep to backtracking for visualisation

---
 window.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/window.cpp b/window.cpp
index 14d137e..d023533 100644
--- a/window.cpp
+++ b/window.cpp
@@ -58,6 +58,8 @@ Window::Window(QWidget *parent)
             {
                 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(undo(int)), &m_cell[x1 + y1 * 9], SLOT(addOption(int)));
@@ -74,6 +76,8 @@ void Window::solveButtonClicked()
     srand(time(NULL)); //random seed
     while (1)
     {
+        repaint(); // draw cells again
+        QThread::msleep(m_delay);
         if (backtracking)
         {
             hist.back()->cell->un();
@@ -84,6 +88,8 @@ void Window::solveButtonClicked()
             }
             backtracking = false;
             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;
             std::vector<int>::iterator it;
             it = hist.back()->index.begin() + choiceNr;
@@ -128,8 +134,6 @@ void Window::solveButtonClicked()
             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;
         }
-        repaint(); // draw cells again
-        QThread::msleep(m_delay);
     }
     // qInfo("%d---:)");
 }
@@ -141,7 +145,6 @@ void Window::clearButtonClicked()
         if (x.collapsed)
             x.un();
     }
-    repaint();
     return;
 }
 void Window::setValue(int s)
-- 
GitLab