-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_maze_ing.py
More file actions
80 lines (74 loc) · 2.4 KB
/
a_maze_ing.py
File metadata and controls
80 lines (74 loc) · 2.4 KB
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
#!/usr/bin/env python3
import os
import random
from ascii_map.data_submitter import submit_data
from config import parse_config, validate_config
from display import THEMES, render_tui, animate_solution
from mazegen import create_generator, maze_solver
def main() -> None:
config = validate_config(parse_config("config.txt"))
maze = create_generator(
config["WIDTH"],
config["HEIGHT"],
config["SEED"],
config["PERFECT"],
)
maze.generate()
theme = THEMES[37]
show_path: bool = False
path, path_directions = maze_solver(
maze.grid, config["ENTRY"], config["EXIT"]
)
submit_data(config, maze, path_directions)
try:
while True:
os.system("clear")
render_tui(
maze.grid,
maze.width,
maze.height,
maze.locked,
path if show_path else None,
config["ENTRY"],
config["EXIT"],
theme,
)
print(f"{theme['WALL_COLOR']}\033[49m", end="")
print("1) Regenerate")
print(f"2) Change theme [current: {theme['name']}]")
print("3) Toggle path")
print("4) Animate solution")
print("5) Quit")
choice = input("Choose (based on number): ")
print("\033[0m") # reset color
if choice == "1":
maze.generate()
path, path_directions = maze_solver(
maze.grid, config["ENTRY"], config["EXIT"]
)
submit_data(config, maze, path_directions)
elif choice == "2":
theme = random.choice([t for t in THEMES if t != theme])
elif choice == "3":
show_path = False if show_path else True
elif choice == "4":
animate_solution(
maze.grid,
maze.width,
maze.height,
maze.locked,
path,
config["ENTRY"],
config["EXIT"],
theme,
)
show_path = True
elif choice == "5":
print("See ya!")
exit(0)
except (KeyboardInterrupt, EOFError):
pass
except Exception as e:
print(f"[ERROR]: {e}")
if __name__ == "__main__":
main()