Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nrossol
Sudoku Backtracking
Commits
77dcb603
Commit
77dcb603
authored
Sep 04, 2020
by
nrossol
Browse files
Implemented clicking feature to reveal a square's solution.
parent
3578d573
Changes
2
Hide whitespace changes
Inline
Side-by-side
gui.py
View file @
77dcb603
#GUI for sudoku solver by Nathan Rossol, Computer Science sophomore at the University of Michigan
from
sudokuSolverPython
import
solveSudoku
from
sudokuSolverPython
import
solveSudoku
,
solve
import
pygame
import
os
g
rid
=
[
[
3
,
2
,
1
,
0
,
5
,
0
,
9
,
4
,
7
],
tempG
rid
=
[
[
3
,
2
,
1
,
0
,
5
,
0
,
9
,
4
,
7
],
[
7
,
8
,
0
,
0
,
1
,
0
,
0
,
6
,
5
],
[
0
,
0
,
6
,
7
,
0
,
4
,
1
,
0
,
0
],
[
5
,
4
,
9
,
0
,
0
,
0
,
7
,
8
,
6
],
...
...
@@ -13,6 +13,19 @@ grid = [ [ 3, 2, 1, 0, 5, 0, 9, 4, 7 ],
[
0
,
3
,
0
,
2
,
0
,
7
,
0
,
5
,
0
],
[
2
,
0
,
7
,
0
,
4
,
0
,
8
,
0
,
3
]
]
solvedGrid
=
[
[
3
,
2
,
1
,
0
,
5
,
0
,
9
,
4
,
7
],
[
7
,
8
,
0
,
0
,
1
,
0
,
0
,
6
,
5
],
[
0
,
0
,
6
,
7
,
0
,
4
,
1
,
0
,
0
],
[
5
,
4
,
9
,
0
,
0
,
0
,
7
,
8
,
6
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
9
,
0
,
6
,
0
,
0
,
0
],
[
1
,
0
,
5
,
0
,
6
,
0
,
4
,
0
,
2
],
[
0
,
3
,
0
,
2
,
0
,
7
,
0
,
5
,
0
],
[
2
,
0
,
7
,
0
,
4
,
0
,
8
,
0
,
3
]
]
solve
(
solvedGrid
)
#Basic Colors:
BLACK
=
(
0
,
0
,
0
)
WHITE
=
(
255
,
255
,
255
)
...
...
@@ -33,9 +46,14 @@ clock = pygame.time.Clock()
#Main Loop:
done
=
False
while
not
done
:
#event detection:
clicked
=
False
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
done
=
True
if
event
.
type
==
pygame
.
MOUSEBUTTONUP
:
clicked
=
True
pos
=
pygame
.
mouse
.
get_pos
()
screen
.
fill
(
BLACK
)
...
...
@@ -45,10 +63,18 @@ while not done:
pygame
.
draw
.
rect
(
screen
,
WHITE
,
(
i
,
j
,
box_size
,
box_size
),
0
)
pygame
.
draw
.
rect
(
screen
,
WHITE
,
(
0
,
495
,
490
,
100
),
0
)
#mouse click:
if
clicked
:
print
(
"CLICKED"
)
if
pos
[
1
]
<
screen_height
:
row
=
int
(
pos
[
0
]
/
(
box_size
+
margin
))
col
=
int
(
pos
[
1
]
/
(
box_size
+
margin
))
tempGrid
[
row
][
col
]
=
solvedGrid
[
row
][
col
]
#fill in grid:
for
i
in
range
(
0
,
9
):
for
j
in
range
(
0
,
9
):
number_surface
=
font
.
render
(
str
(
g
rid
[
i
][
j
]),
False
,
(
0
,
0
,
0
))
number_surface
=
font
.
render
(
str
(
tempG
rid
[
i
][
j
]),
False
,
(
0
,
0
,
0
))
screen
.
blit
(
number_surface
,
(
7
+
i
*
(
box_size
+
margin
),
7
+
j
*
(
box_size
+
margin
)))
#update display
...
...
sudokuSolverPython.py
View file @
77dcb603
...
...
@@ -93,6 +93,6 @@ def solve(grid):
else
:
print
(
"Unsolvable :("
)
printBoard
(
grid
)
#printBoard(grid)
#return grid;
solve
(
grid
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment