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

changed m_cells array to be array of cells instead of cell pointers

parent e4cf0a7b
Branches
Tags
1 merge request!1Master
...@@ -36,8 +36,8 @@ Window::Window(QWidget *parent) ...@@ -36,8 +36,8 @@ Window::Window(QWidget *parent)
dy = 4; dy = 4;
if (y >= 6) if (y >= 6)
dy = 8; dy = 8;
m_cell[x+y*9] = new Cell(this); m_cell[x+y*9].setParent(this);
m_cell[x+y*9]->setGeometry(x * 100 + dx, y * 100 + dy, 100, 100); m_cell[x+y*9].setGeometry(x * 100 + dx, y * 100 + dy, 100, 100);
/* code */ /* code */
} }
} }
...@@ -48,11 +48,11 @@ Window::Window(QWidget *parent) ...@@ -48,11 +48,11 @@ Window::Window(QWidget *parent)
{ {
for (int d = 0; d < 9; d++) //rows and columns 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[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[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[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[d+y*9], SLOT(addOption(int)));
} }
int a = x / 3 * 3; int a = x / 3 * 3;
int b = y / 3 * 3; int b = y / 3 * 3;
...@@ -60,9 +60,9 @@ Window::Window(QWidget *parent) ...@@ -60,9 +60,9 @@ Window::Window(QWidget *parent)
{ {
for (int y1 = b; y1 < b + 3; y1++) 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) ...@@ -71,6 +71,7 @@ Window::Window(QWidget *parent)
void Window::solveButtonClicked() void Window::solveButtonClicked()
{ {
std::array<Cell,81> start = m_cell;
srand(time(NULL)); srand(time(NULL));
while (1) while (1)
{ {
...@@ -80,17 +81,17 @@ void Window::solveButtonClicked() ...@@ -80,17 +81,17 @@ void Window::solveButtonClicked()
{ {
for (int y = 0; y < 9; y++) for (int y = 0; y < 9; y++)
{ {
if (m_cell[x+y*9]->collapsed) if (m_cell[x+y*9].collapsed)
continue; 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.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]);
} }
} }
} }
......
...@@ -17,8 +17,7 @@ private: ...@@ -17,8 +17,7 @@ private:
QPushButton *grid[9][9]; QPushButton *grid[9][9];
QProgressBar *m_progressBar; QProgressBar *m_progressBar;
QSlider *m_slider; QSlider *m_slider;
//Cell *m_cell[9][9]; std::array<Cell,81> m_cell;
std::array<Cell *,81> m_cell;
int m_delay =300; int m_delay =300;
signals: signals:
void counterReached(); void counterReached();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment