diff --git a/window.cpp b/window.cpp index 931a4796dd2b8f6d298ae25361c146be5c4e8d3d..90141c95001d8895fe7c11b25d1dced91d46199d 100644 --- a/window.cpp +++ b/window.cpp @@ -36,8 +36,8 @@ Window::Window(QWidget *parent) dy = 4; if (y >= 6) dy = 8; - m_cell[x+y*9] = new Cell(this); - m_cell[x+y*9]->setGeometry(x * 100 + dx, y * 100 + dy, 100, 100); + m_cell[x+y*9].setParent(this); + m_cell[x+y*9].setGeometry(x * 100 + dx, y * 100 + dy, 100, 100); /* code */ } } @@ -48,11 +48,11 @@ Window::Window(QWidget *parent) { for (int d = 0; d < 9; d++) //rows and columns { - connect(m_cell[x+y*9], SIGNAL(update(int)), m_cell[x+d*9], SLOT(removeOption(int))); - connect(m_cell[x+y*9], SIGNAL(update(int)), m_cell[d+y*9], SLOT(removeOption(int))); + connect(&m_cell[x+y*9], SIGNAL(update(int)), &m_cell[x+d*9], SLOT(removeOption(int))); + connect(&m_cell[x+y*9], SIGNAL(update(int)), &m_cell[d+y*9], SLOT(removeOption(int))); - connect(m_cell[x+y*9], SIGNAL(undo(int)), m_cell[x+d*9], SLOT(addOption(int))); - connect(m_cell[x+y*9], SIGNAL(undo(int)), m_cell[d+y*9], SLOT(addOption(int))); + connect(&m_cell[x+y*9], SIGNAL(undo(int)), &m_cell[x+d*9], SLOT(addOption(int))); + connect(&m_cell[x+y*9], SIGNAL(undo(int)), &m_cell[d+y*9], SLOT(addOption(int))); } int a = x / 3 * 3; int b = y / 3 * 3; @@ -60,9 +60,9 @@ Window::Window(QWidget *parent) { for (int y1 = b; y1 < b + 3; y1++) { - 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))); } } } @@ -71,6 +71,7 @@ Window::Window(QWidget *parent) void Window::solveButtonClicked() { + std::array<Cell,81> start = m_cell; srand(time(NULL)); while (1) { @@ -80,17 +81,17 @@ void Window::solveButtonClicked() { for (int y = 0; y < 9; y++) { - if (m_cell[x+y*9]->collapsed) + if (m_cell[x+y*9].collapsed) continue; - else if (m_cell[x+y*9]->possibleStates < minEtropy) + else if (m_cell[x+y*9].possibleStates < minEtropy) { - minEtropy = m_cell[x+y*9]->possibleStates; + minEtropy = m_cell[x+y*9].possibleStates; b.clear(); - b.push_back(m_cell[x+y*9]); + b.push_back(&m_cell[x+y*9]); } - else if (m_cell[x+y*9]->possibleStates == minEtropy) + else if (m_cell[x+y*9].possibleStates == minEtropy) { - b.push_back(m_cell[x+y*9]); + b.push_back(&m_cell[x+y*9]); } } } diff --git a/window.h b/window.h index 0cccb2fa461aae2f02ec290fc2cd1b1234128e30..3127c7e2675b3575f488d648501efce57c402e64 100644 --- a/window.h +++ b/window.h @@ -17,8 +17,7 @@ private: QPushButton *grid[9][9]; QProgressBar *m_progressBar; QSlider *m_slider; - //Cell *m_cell[9][9]; - std::array<Cell *,81> m_cell; + std::array<Cell,81> m_cell; int m_delay =300; signals: void counterReached();