-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku_solver_gui.py
103 lines (65 loc) · 2.63 KB
/
sudoku_solver_gui.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Code is written by ÖZER TANRISEVER
#Credit : https://www.linkedin.com/in/ozer-tanrisever/
import pygame
import time
import sudoku_solver as ss
def show_board():
'''This method draws the board layout.'''
for i in range(0,10):
if(i%3 ==0):
punto = 4
else:
punto = 1
pygame.draw.line(gameDisplay,(0,0,0),(0,i*((width)/9)),(height,i*((width)/9)),punto)
pygame.draw.line(gameDisplay,(0,0,0),(i*((width)/9),0),(i*((width)/9),height),punto)
def print_original_board():
'''This method prints the non played (original) board.'''
board_numbers = []
for i in ss.board:
for j in i[:]:
board_numbers.append(j)
board_numbers.reverse()
num_loc = []
x=0
for i in range(0,9):
for i in range(0,9):
num_loc.append([int(i*((width)/9)),x])
x += 100
for i in range(1,82):
if(board_numbers[i-1] != 0 ):
font = pygame.font.SysFont(None, 100)
text = font.render(str(board_numbers[i-1]), True, (45,8,140,250))
gameDisplay.blit(text,(num_loc[-i][0]+33,num_loc[-i][1]+20))
pygame.display.update()
clock.tick(12)
def sudoku_gui_number_update(squareX,squareY,new_number):
'''This method puts a number to spesific location on the board and makes its background green.'''
square_size = 100
pygame.draw.rect(gameDisplay,(0,255,0),(squareX,squareY,square_size,square_size))
font = pygame.font.SysFont(None, 100)
text = font.render(str(new_number), False, (45,8,140,250))
gameDisplay.blit(text,(squareX+33,squareY+20))
show_board()
pygame.display.update()
clock.tick(12)
def sudoku_gui_number_delete(squareX,squareY):
'''This method clears a square and makes red bordered! '''
square_size = 100
pygame.draw.rect(gameDisplay,(255,0,0),(squareX+1,squareY+1,square_size-1,square_size-1))
pygame.draw.rect(gameDisplay,(255,255,255),(squareX+5,squareY+5,square_size-9,square_size-9))
pygame.display.update()
clock.tick(12)
pygame.init()
clock = pygame.time.Clock()
height = width = 900
gameDisplay = pygame.display.set_mode((height,width))
pygame.display.set_caption('Sudoku_Solver_made_by_Özer_TANRISEVER')
pygame.draw.rect(gameDisplay,(255,255,255),(0,0,height,width))
show_board()
print_original_board()
while(ss.find_empty_square_index() != None):
r,c = ss.find_empty_square_index()
ss.assign_a_number(r,c)
clock.tick(12)
time.sleep(3)
pygame.quit()