-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplaySol.py
87 lines (58 loc) · 1.49 KB
/
displaySol.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
import tkinter as tk
master = tk.Tk()
master.title("N Queens Problem")
colour1 = 'white'
colour2 = 'teal'
dummyImg = tk.PhotoImage()
queenPhoto = tk.PhotoImage(file='queenImg.png')
queenIco = tk.PhotoImage(file='queenIco.png')
master.tk.call('wm', 'iconphoto', master._w, queenIco)
def displayGUI(N):
colour = colour1
with open('N_Queen_To_SAT.sol', mode='r') as f:
content = f.read().splitlines()
f.close()
solved = content[0]
if solved=='UNSAT':
print("This problem is unsolvable for N = %d" %N)
return
result = content[1].split()
r = -1
c = 0
for i in range(N*N):
if (i%N) == 0:
r += 1
c = 0
if (N%2) == 0:
colour = colour1 if colour == colour2 else colour2
tile = int(result[i])
if tile < 0:
tk.Label(master, bg=colour, image=dummyImg, width=32, height=32, compound='center').grid(row=r,column=c)
else:
tk.Label(master, bg=colour, image=queenPhoto, width=32, height=32, compound='center').grid(row=r,column=c)
c += 1
colour = colour1 if colour == colour2 else colour2
master.mainloop()
def displayNonGUI(N):
with open('N_Queen_To_SAT.sol', mode='r') as f:
content = f.read().splitlines()
f.close()
solved = content[0]
if solved=='UNSAT':
print("This problem is unsolvable for N = %d" %N)
return
result = content[1].split()
r = -1
c = 0
for i in range(N*N):
if (i%N) == 0:
r += 1
c = 0
print('')
tile = int(result[i])
if tile < 0:
print(" _ ", end="")
else:
print(" X ", end="")
c += 1
print('\n')