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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Silas Dohm
sudoku solver
Commits
503e6f21
Commit
503e6f21
authored
2 years ago
by
Silas Dohm
Browse files
Options
Downloads
Patches
Plain Diff
clear sodoku button added, renamed vars
parent
4fff46bf
Branches
Branches containing commit
No related tags found
1 merge request
!2
backtracking
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
window.cpp
+19
-8
19 additions, 8 deletions
window.cpp
window.h
+3
-2
3 additions, 2 deletions
window.h
with
22 additions
and
10 deletions
window.cpp
+
19
−
8
View file @
503e6f21
...
...
@@ -10,14 +10,18 @@ Window::Window(QWidget *parent)
:
QWidget
{
parent
}
{
setFixedWidth
(
1600
);
m_button
=
new
QPushButton
(
"solve"
,
this
);
connect
(
m_button
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
solveButtonClicked
()));
m_button
->
setGeometry
(
1200
,
height
()
-
30
,
width
()
-
1200
,
30
);
m_solveButton
=
new
QPushButton
(
"solve"
,
this
);
m_solveButton
->
setGeometry
(
1100
,
height
()
-
100
,
width
()
-
1200
,
30
);
connect
(
m_solveButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
solveButtonClicked
()));
m_clearButton
=
new
QPushButton
(
"Clear"
,
this
);
m_clearButton
->
setGeometry
(
1100
,
height
()
-
30
,
width
()
-
1200
,
30
);
connect
(
m_clearButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
clearButtonClicked
()));
m_slider
=
new
QSlider
(
this
);
m_slider
->
setRange
(
0
,
1000
);
m_slider
->
setOrientation
(
Qt
::
Horizontal
);
m_slider
->
setValue
(
m_delay
);
m_slider
->
setGeometry
(
1
2
00
,
height
()
-
60
,
width
()
-
1200
,
30
);
m_slider
->
setGeometry
(
1
1
00
,
height
()
-
60
,
width
()
-
1200
,
30
);
connect
(
m_slider
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
setValue
(
int
)));
int
dx
=
0
;
...
...
@@ -72,11 +76,11 @@ Window::Window(QWidget *parent)
void
Window
::
solveButtonClicked
()
{
std
::
list
<
History
*>
hist
;
bool
end
=
false
;
bool
backtracking
=
false
;
srand
(
time
(
NULL
));
while
(
1
)
{
if
(
end
)
if
(
backtracking
)
{
hist
.
back
()
->
cell
->
un
();
if
(
hist
.
back
()
->
index
.
size
()
==
0
)
...
...
@@ -84,7 +88,7 @@ void Window::solveButtonClicked()
hist
.
pop_back
();
continue
;
}
end
=
false
;
backtracking
=
false
;
int
choiceNr
=
rand
()
%
hist
.
back
()
->
index
.
size
();
// choose a random number;
hist
.
back
()
->
cell
->
collapse
(
hist
.
back
()
->
index
[
choiceNr
]);
// collapse cell with chosen number;
std
::
vector
<
int
>::
iterator
it
;
...
...
@@ -121,7 +125,7 @@ void Window::solveButtonClicked()
else
if
(
minEtropy
==
0
)
{
qInfo
(
"backtracking"
);
end
=
true
;
backtracking
=
true
;
continue
;
}
...
...
@@ -136,6 +140,13 @@ void Window::solveButtonClicked()
// qInfo("%d---:)");
}
void
Window
::
clearButtonClicked
(){
for
(
auto
&
x
:
m_cell
){
if
(
x
.
collapsed
)
x
.
un
();
}
return
;
}
void
Window
::
setValue
(
int
s
)
{
m_delay
=
s
;
...
...
This diff is collapsed.
Click to expand it.
window.h
+
3
−
2
View file @
503e6f21
...
...
@@ -13,8 +13,8 @@ public:
explicit
Window
(
QWidget
*
parent
=
nullptr
);
private:
QPushButton
*
m_
b
utton
Quit
;
QPushButton
*
m_
b
utton
;
QPushButton
*
m_
clearB
utton
;
QPushButton
*
m_
solveB
utton
;
QPushButton
*
grid
[
9
][
9
];
QProgressBar
*
m_progressBar
;
QSlider
*
m_slider
;
...
...
@@ -40,6 +40,7 @@ signals:
private
slots
:
void
setValue
(
int
s
);
void
solveButtonClicked
();
void
clearButtonClicked
();
};
#endif // WINDOW_H
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