-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (39 loc) · 1.42 KB
/
main.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
import sys
from collections import defaultdict
from kamertje_verhuren import KamertjeVerhuren
from sudoku import Sudoku
if __name__ == "__main__":
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = 'puzzels/1.sudoku.txt'
if filename.endswith('.sudoku.txt'):
Solver = Sudoku
elif filename.endswith('.sudokuchaos.txt'):
Solver = Sudoku
elif filename.endswith('.kvh.txt'):
Solver = KamertjeVerhuren
with open(filename, 'r') as infile:
solver = Solver.parse(infile)
print(solver.getState())
used_rules = defaultdict(int)
while not solver.solved():
for rule in solver.rules:
changes = rule()
if changes:
used_rules[rule.__name__] += changes
print('{} caused {} changes'.format(rule.__name__, changes))
print('--------------------')
print(solver.getState())
print('====================')
# we want to start over again with rule one
break
if changes == 0:
#applying rules has no more effect, so stop anyhow
break
if solver.solved():
print('YAYYYYY!')
else:
print('Awwwwww...')
for rule, score in used_rules.items():
print('{: <30}\t{: >3}'.format(rule, score))