-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (36 loc) · 1.91 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
import argparse
from window import Window
from cell import Cell
from maze import Maze
def main():
parser = argparse.ArgumentParser(description='Maze Solver')
parser.add_argument('--columns', type=int, default=20,
help='Number of columns in the maze')
parser.add_argument('--rows', type=int, default=20,
help='Number of rows in the maze')
parser.add_argument('--algorithm', type=str, default='iterative',
help='Choose if the generation and solving should be performed recursively or iteratively: recursive, iterative')
parser.add_argument('--width', type=int, default=800,
help='Window width in pixels')
parser.add_argument('--height', type=int, default=800,
help='Window height in pixels')
parser.add_argument('--slow', action='store_true',
help='Run the program in slow mode so the programs work is easier to follow. For large mazes it can get a bit slow anyway :)')
args = parser.parse_args()
if args.algorithm not in ['recursive', 'iterative']:
raise ValueError('Algorithm must be either "recursive" or "iterative"')
win = Window(f"Maze Solver - Size: {args.columns}x{args.rows} Algorithm: {args.algorithm}", args.width, args.height)
# Pass win to Maze and Cell class so they can use it to draw themselves
Maze.set_win(win)
Cell.set_win(win)
# Calculate and set wall length to use based on maze and window size
cell_wall_length = max(args.width / args.columns, args.height / args.rows)
Cell.set_wall_length(cell_wall_length)
if args.algorithm == 'recursive':
import sys
sys.setrecursionlimit(max(sys.getrecursionlimit(), args.columns * args.rows))
maze = Maze(1, 1, args.rows, args.columns, args.algorithm, args.slow)
maze.solve()
win.wait_for_close()
if __name__ == '__main__':
main()