-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (59 loc) · 1.47 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
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
from os import system
from myio import *
from puzzle import Puzzle
def clear():
system('cls')
return
class Game():
def __init__(self, it_lim:int, random_board:bool):
self.it_lim = it_lim
self.random_board = random_board
self.puzzle = Puzzle()
def start(self):
self.puzzle.it_lim = self.it_lim
if self.random_board:
self.puzzle.reset_board()
self.puzzle.shuffle_board()
else:
clear()
print('\n\tInitial Node')
print(self.puzzle.initial)
if input('\n\tProvide a new board (Y/ANY)? ').lower() == 'y':
self.puzzle.accept(read())
clear()
print('\n\tInitial Node')
print(self.puzzle.initial)
path = self.puzzle.solve()
if path[1] >= 0:
steps = len(path[0]) - 1
if steps == 0:
print("\n\tNo change is required, the board is sorted.")
else:
print(f'''\n\t{self.puzzle.it_done} iterations needed.\n\n\tResolution Path - {steps} steps.''')
for node in path[0]:
print(node)
else:
print(f'''\n\tNo solution was found after {self.puzzle.it_done} iterations.\n''')
input('\n\tENTER to continue.')
return
def configure(self):
self.it_lim, self.random_board = settings()
return
def run(self):
while True:
clear()
banner(self.it_lim, self.random_board)
user_op = menu().lower()
clear()
if user_op == '1':
self.start()
elif user_op == '2':
self.configure()
elif user_op == '3':
helpbanner()
else:
break
return
if __name__ == '__main__':
game = Game(100000, True)
game.run()