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

renamed vars

parent 9b5c6ee1
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ Cell::Cell(QWidget *parent) : QWidget(parent)
m_groupBox->setLayout(m_gridLayout);
m_number = new QPushButton(this);
connect(m_number, SIGNAL(clicked()), this, SLOT(un()));
connect(m_number, SIGNAL(clicked()), this, SLOT(collapsedCellClicked()));
m_stackedWidget = new QStackedWidget(this);
m_stackedWidget->addWidget(m_groupBox);
m_stackedWidget->addWidget(m_number);
......@@ -57,7 +57,7 @@ void Cell::removeOption(int x)
m_states[x]->setText(" ");
m_states[x]->setDisabled(true);
possibleStates--;
index.erase(std::find(index.begin(), index.end(), x));
options.erase(std::find(options.begin(), options.end(), x));
}
m_blocked[x]++;
}
......@@ -71,10 +71,10 @@ void Cell::addOption(int x)
m_states[x]->setText(QString::number(x + 1));
m_states[x]->setDisabled(false);
possibleStates++;
index.push_back(x);
options.push_back(x);
}
}
void Cell::un(void)
void Cell::collapsedCellClicked(void)
{
collapsed = false;
m_stackedWidget->setCurrentIndex(0);
......
......@@ -15,7 +15,7 @@ public:
void resizeEvent(QResizeEvent *event);
int possibleStates = 9;
bool collapsed = false;
std::vector<int> index = {0, 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int> options = {0, 1, 2, 3, 4, 5, 6, 7, 8};
private:
QSignalMapper *m_mapper;
......@@ -33,7 +33,7 @@ public slots:
void addOption(int x);
void removeOption(int x);
void collapse(int x);
void un(void);
void collapsedCellClicked(void);
};
#endif // CELL_H
\ No newline at end of file
......@@ -24,24 +24,24 @@ Window::Window(QWidget *parent)
m_slider->setValue(m_delay);
connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
horizontalLayout = new QHBoxLayout(this);
verticalLayout = new QVBoxLayout();
layout = new QGridLayout();
m_horizontalLayout = new QHBoxLayout(this);
m_verticalLayout = new QVBoxLayout();
m_layout = new QGridLayout();
m_spacer[0] = new QSpacerItem(4, 4, QSizePolicy::Minimum, QSizePolicy::Fixed);
m_spacer[1] = new QSpacerItem(4, 4, QSizePolicy::Minimum, QSizePolicy::Fixed);
m_spacer[2] = new QSpacerItem(8, 8, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(m_spacer[2]);
m_verticalLayout->addItem(m_spacer[2]);
verticalLayout->addWidget(m_solveButton);
verticalLayout->addWidget(m_slider);
verticalLayout->addWidget(m_clearButton);
horizontalLayout->addLayout(layout, 5);
horizontalLayout->addLayout(verticalLayout, 1);
m_verticalLayout->addWidget(m_solveButton);
m_verticalLayout->addWidget(m_slider);
m_verticalLayout->addWidget(m_clearButton);
m_horizontalLayout->addLayout(m_layout, 5);
m_horizontalLayout->addLayout(m_verticalLayout, 1);
layout->addItem(m_spacer[0], 3, 3);
layout->addItem(m_spacer[1], 7, 7);
layout->setSpacing(0);
m_layout->addItem(m_spacer[0], 3, 3);
m_layout->addItem(m_spacer[1], 7, 7);
m_layout->setSpacing(0);
int dx = 0;
int dy = 0;
......@@ -50,7 +50,7 @@ Window::Window(QWidget *parent)
for (int y = 0; y < 9; y++)
{
m_cell[x + y * 9].setParent(this);
layout->addWidget(&m_cell[x + y * 9], y + y / 3, x + x / 3);
m_layout->addWidget(&m_cell[x + y * 9], y + y / 3, x + x / 3);
// connecting signals & slots
for (int d = 0; d < 9; d++) // rows and columns
{
......@@ -88,20 +88,20 @@ void Window::solveButtonClicked()
delay(m_delay);
if (backtracking)
{
hist.back().cell->un();
if (hist.back().index.size() == 0)
hist.back().cell->collapsedCellClicked();
if (hist.back().options.size() == 0)
{
hist.pop_back();
continue;
}
backtracking = false;
int choiceNr = rand() % hist.back().index.size(); // choose a random number;
int choiceNr = rand() % hist.back().options.size(); // choose a random number;
repaint(); // draw cells again
delay(m_delay);
hist.back().cell->collapse(hist.back().index[choiceNr]); // collapse cell with chosen number;
hist.back().cell->collapse(hist.back().options[choiceNr]); // collapse cell with chosen number;
std::vector<int>::iterator it;
it = hist.back().index.begin() + choiceNr;
hist.back().index.erase(it);
it = hist.back().options.begin() + choiceNr;
hist.back().options.erase(it);
}
else
{
......@@ -138,12 +138,11 @@ void Window::solveButtonClicked()
}
int choiceCell = rand() % b.size(); // choose a random cell
int choiceNr = rand() % b[choiceCell]->index.size(); // choose a random number;
hist.push_back(History(b[choiceCell], b[choiceCell]->index, choiceNr));
b[choiceCell]->collapse(b[choiceCell]->index[choiceNr]); // collapse that random cell with chosen number;
int choiceNr = rand() % b[choiceCell]->options.size(); // choose a random number;
hist.push_back(History(b[choiceCell], b[choiceCell]->options, choiceNr));
b[choiceCell]->collapse(b[choiceCell]->options[choiceNr]); // collapse that random cell with chosen number;
}
}
// qInfo("%d---:)");
}
inline void Window::delay(int millisecondsWait)
{
......@@ -158,7 +157,7 @@ void Window::clearButtonClicked()
for (auto &x : m_cell)
{
if (x.collapsed)
x.un();
x.collapsedCellClicked();
}
return;
}
......
......@@ -22,13 +22,13 @@ private:
std::array<Cell, 81> m_cell;
int m_delay = 300;
QSpacerItem *m_spacer[3];
QHBoxLayout *horizontalLayout;
QVBoxLayout *verticalLayout;
QGridLayout *layout;
QHBoxLayout *m_horizontalLayout;
QVBoxLayout *m_verticalLayout;
QGridLayout *m_layout;
struct History
{
Cell *cell;
std::vector<int> index;
std::vector<int> options;
History(Cell *c, std::vector<int> in, int choice)
{
cell = c;
......@@ -36,7 +36,7 @@ private:
{
if (i == choice)
continue;
index.push_back(in[i]);
options.push_back(in[i]);
}
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment