-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (48 loc) · 1.53 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
from search import *
from graph_traversal import *
from utils.state_properties import *
from utils.state_gen import *
from play import play
def main(state):
print("Current starting state is:")
print(state)
try:
print("Puzzle has "+str(num_pegs(state))+" pegs, and "+str(num_discs(state))+" discs.")
assert validate_state(state)
except:
print("Puzzle state invalid. Please try again.")
make_state(state)
print("You may:")
print(" - (c)hange starting state")
print(" - (p)lay with this state")
print(" - generate full (g)raph")
print(" - (a)utomatically solve")
choice = input("(c)hange/(p)lay/(g)raph/(a)utosolve: ")
if choice == "c":
make_state(state)
elif choice == "p":
play(state)
elif choice == "g":
generate_graph(state)
elif choice == "a":
autosolve(state)
def autosolve(state):
print('Initial State of puzzle:')
print(state)
print("Ready to execute state search?")
choice = input("(y)es/(m)enu: ")
if choice == "y":
print("Solving with BFS")
solution_path = bfs(state)
solution_path.reverse() # Reverse the path to display the solution
print("Path to solution:")
for i, node in enumerate(solution_path):
print(f"Step {i}") # Print the step we are up to in the puzzle solution
print(node)
elif choice == "m":
main()
else:
print("Invalid input")
autosolve(state)
# Initialize a basic puzzle
main([[5, 4, 3, 2, 1], [], []])