From adbac78bd53d0692552817ac0b954f01b056cc7b Mon Sep 17 00:00:00 2001
From: Silas Dohm <silas.dohm@stud.hs-bochum.de>
Date: Thu, 25 Aug 2022 02:40:30 +0200
Subject: [PATCH] refactor

---
 window.cpp | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/window.cpp b/window.cpp
index f5310a8..a35cca8 100644
--- a/window.cpp
+++ b/window.cpp
@@ -108,29 +108,24 @@ void Window::solveButtonClicked()
         {
             std::vector<Cell *> b; // vector of cells with least entropy
             int minEtropy = 10;
-            for (int x = 0; x < 9; x++) // loop through all cells and fill list b --> this could be optimzed
+            for (auto &cell : grid)
             {
-                for (int y = 0; y < 9; y++)
+                if (cell.collapsed)
+                    continue;
+                else if (cell.possibleStates < minEtropy)
                 {
-                    if (grid[x + y * 9].collapsed)
-                        continue;
-                    else if (grid[x + y * 9].possibleStates < minEtropy)
-                    {
-                        minEtropy = grid[x + y * 9].possibleStates;
-                        b.clear();
-                        b.push_back(&grid[x + y * 9]);
-                    }
-                    else if (grid[x + y * 9].possibleStates == minEtropy)
-                    {
-                        b.push_back(&grid[x + y * 9]);
-                    }
+                    minEtropy = cell.possibleStates;
+                    b.clear();
+                    b.push_back(&cell);
+                }
+                else if (cell.possibleStates == minEtropy)
+                {
+                    b.push_back(&cell);
                 }
             }
             if (b.size() == 0) // if b is empty -> solved
-            {
-                qInfo("Solved!!");
                 return;
-            }
+
             else if (minEtropy == 0)
             {
                 qInfo("backtracking");
-- 
GitLab