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
a7fdde24
Commit
a7fdde24
authored
2 years ago
by
Silas Dohm
Browse files
Options
Downloads
Patches
Plain Diff
aligned with other branch
parent
b7af9f93
Branches
main
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
window.cpp
+40
-40
40 additions, 40 deletions
window.cpp
window.h
+4
-4
4 additions, 4 deletions
window.h
with
44 additions
and
44 deletions
window.cpp
+
40
−
40
View file @
a7fdde24
...
...
@@ -83,8 +83,7 @@ void Window::solveButtonClicked()
srand
(
time
(
NULL
));
// random seed
while
(
1
)
{
repaint
();
// draw cells again
delay
(
delayTime
);
delay
();
if
(
backtracking
)
{
hist
.
back
().
cell
->
collapsedCellClicked
();
...
...
@@ -94,18 +93,18 @@ void Window::solveButtonClicked()
validNrs
.
push_back
(
i
);
if
(
validNrs
.
size
()
==
0
)
{
if
(
hist
.
size
()
<=
0
)
return
;
hist
.
pop_back
();
continue
;
}
backtracking
=
false
;
int
rndNr
=
rand
()
%
validNrs
.
size
();
// choose a random number;
repaint
();
// draw cells again
delay
(
delayTime
);
delay
();
hist
.
back
().
cell
->
collapse
(
validNrs
[
rndNr
]);
// collapse cell with chosen number;
hist
.
back
().
blocked
[
validNrs
[
rndNr
]]
++
;
delay
();
}
else
{
std
::
vector
<
Cell
*>
b
;
// vector of cells with least entropy
int
minEtropy
=
10
;
for
(
auto
&
cell
:
grid
)
...
...
@@ -128,7 +127,6 @@ void Window::solveButtonClicked()
else
if
(
minEtropy
==
0
)
{
// qInfo("backtracking");
backtracking
=
true
;
continue
;
}
...
...
@@ -141,17 +139,19 @@ void Window::solveButtonClicked()
validNrs
.
push_back
(
i
);
}
int
rndNr
=
rand
()
%
validNrs
.
size
();
// choose a random number;
hist
.
push_back
(
History
(
b
[
rndCell
],
b
[
rndCell
]
->
blocked
,
validNrs
[
rndNr
]));
hist
.
push_back
(
History
(
b
[
rndCell
],
validNrs
[
rndNr
]));
b
[
rndCell
]
->
collapse
(
validNrs
[
rndNr
]);
// collapse that random cell with chosen number;
}
}
}
inline
void
Window
::
delay
(
int
millisecondsWait
)
inline
void
Window
::
delay
()
{
if
(
!
delayTime
)
return
;
repaint
();
QEventLoop
loop
;
QTimer
t
;
t
.
connect
(
&
t
,
&
QTimer
::
timeout
,
&
loop
,
&
QEventLoop
::
quit
);
t
.
start
(
millisecondsWait
);
t
.
start
(
delayTime
);
loop
.
exec
();
}
void
Window
::
clearButtonClicked
()
...
...
This diff is collapsed.
Click to expand it.
window.h
+
4
−
4
View file @
a7fdde24
...
...
@@ -29,14 +29,14 @@ private:
{
Cell
*
cell
;
std
::
array
<
int
,
9
>
blocked
;
History
(
Cell
*
c
,
std
::
array
<
int
,
9
>
in
,
int
choice
)
History
(
Cell
*
c
,
int
choice
)
{
cell
=
c
;
blocked
=
in
;
blocked
=
c
->
blocked
;
blocked
[
choice
]
++
;
}
};
inline
void
delay
(
int
millisecondsWait
);
inline
void
delay
();
private
slots
:
void
setValue
(
int
s
);
...
...
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