-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudokuSolverAlgo.py
46 lines (36 loc) · 1.14 KB
/
sudokuSolverAlgo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import copy
from sudokuGenerator import *
# -------- Global board ----------------
Board = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]
]
solvedBoard = copy.deepcopy(Board)
def solve(board):
# end condition:- getting to the end of the board - the function findEmpty return NONE
find = findEmpty(board)
if find is None: # if find != False
return True
else:
row, col = find
for number in range(1, 10):
if validCheck(board, number, (row, col)):
board[row][col] = number
# TODO: need to show it on the GUI
if solve(board):
return True
board[row][col] = 0
# TODO: delete the number in the GUI
return False
def mainSolver(level):
sudokuGenerate(Board, level)
solvedBoard = copy.deepcopy(Board)
solve(solvedBoard)
return solvedBoard