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

1d array

parent 2c0ceaab
No related branches found
No related tags found
1 merge request!1Master
......@@ -31,6 +31,9 @@ Cell::Cell(QWidget *parent) : QWidget(parent)
connect(m_number,SIGNAL(clicked()),this,SLOT(un()));
}
Cell::Cell(const Cell &old_obj){
qInfo("aaa");
}
void Cell::collapse(int x)
{
collapsed = true;
......
......@@ -9,6 +9,7 @@ class Cell : public QWidget
Q_OBJECT
public:
explicit Cell(QWidget *parent = 0);
Cell (const Cell &old_obj);
int possibleStates=9;
bool collapsed = false;
std::vector<int> index={0,1,2,3,4,5,6,7,8};
......
......@@ -36,8 +36,8 @@ Window::Window(QWidget *parent)
dy = 4;
if (y >= 6)
dy = 8;
m_cell[x][y] = new Cell(this);
m_cell[x][y]->setGeometry(x * 100 + dx, y * 100 + dy, 100, 100);
m_cell[x+y*9] = new Cell(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], SIGNAL(update(int)), m_cell[x][d], SLOT(removeOption(int)));
connect(m_cell[x][y], SIGNAL(update(int)), m_cell[d][y], 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], SIGNAL(undo(int)), m_cell[x][d], SLOT(addOption(int)));
connect(m_cell[x][y], SIGNAL(undo(int)), m_cell[d][y], 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], SIGNAL(update(int)), m_cell[x1][y1], 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], SIGNAL(undo(int)), m_cell[x1][y1], SLOT(addOption(int)));
connect(m_cell[x+y*9], SIGNAL(undo(int)), m_cell[x1+y1*9], SLOT(addOption(int)));
}
}
}
......@@ -80,17 +80,17 @@ void Window::solveButtonClicked()
{
for (int y = 0; y < 9; y++)
{
if (m_cell[x][y]->collapsed)
if (m_cell[x+y*9]->collapsed)
continue;
else if (m_cell[x][y]->possibleStates < minEtropy)
else if (m_cell[x+y*9]->possibleStates < minEtropy)
{
minEtropy = m_cell[x][y]->possibleStates;
minEtropy = m_cell[x+y*9]->possibleStates;
b.clear();
b.push_back(m_cell[x][y]);
b.push_back(m_cell[x+y*9]);
}
else if (m_cell[x][y]->possibleStates == minEtropy)
else if (m_cell[x+y*9]->possibleStates == minEtropy)
{
b.push_back(m_cell[x][y]);
b.push_back(m_cell[x+y*9]);
}
}
}
......
......@@ -17,7 +17,8 @@ private:
QPushButton *grid[9][9];
QProgressBar *m_progressBar;
QSlider *m_slider;
Cell *m_cell[9][9];
//Cell *m_cell[9][9];
std::array<Cell *,81> m_cell;
int m_delay =300;
signals:
void counterReached();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment