Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sudoku solver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Silas Dohm
sudoku solver
Commits
88608354
Commit
88608354
authored
2 years ago
by
Silas Dohm
Browse files
Options
Downloads
Patches
Plain Diff
renamed vars
parent
9b5c6ee1
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
cell.cpp
+4
-4
4 additions, 4 deletions
cell.cpp
cell.h
+2
-2
2 additions, 2 deletions
cell.h
window.cpp
+23
-24
23 additions, 24 deletions
window.cpp
window.h
+5
-5
5 additions, 5 deletions
window.h
with
34 additions
and
35 deletions
cell.cpp
+
4
−
4
View file @
88608354
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
cell.h
+
2
−
2
View file @
88608354
...
...
@@ -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
This diff is collapsed.
Click to expand it.
window.cpp
+
23
−
24
View file @
88608354
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
window.h
+
5
−
5
View file @
88608354
...
...
@@ -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
]);
}
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment