-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_interactive.py
59 lines (44 loc) · 1.49 KB
/
main_interactive.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
import algo as solver_algo
import my_maze as maze
import draw_s_path as draw
class the_finder(draw.Finder):
def __init__(self):
self.reset()
def step(self, frames):
"""
This is a function for animating path finding process.
Parameters:
-----------
frames (int): Number of frames to animate from current position
Returns:
--------
None
"""
self.max_distance = max(0, self.max_distance + frames)
self.result = solver_algo.fill_shortest_path(self.wall_maze.board, self.wall_maze.start, self.wall_maze.end, max_distance =self.max_distance)
self.set_board(self.result)
path = solver_algo.backtrack_to_start(self.result, self.wall_maze.end)
self.set_path(path)
def reset(self):
"""
Resets the maze to its initial state with walls, and sets the maximum distance.
Parameters:
-----------
self (object):
The instance of the class from which this method is called. It modifies the `wall_maze`, `max_distance`, and calls the `step` method on itself.
Returns:
--------
None
"""
self.wall_maze = maze.create_wall_maze(30, 22)
self.max_distance = 30
self.step(0)
menu_text = """Keys:
Left - Lower maximum distance
Right - Increase maximum distance
R - create a new maze
Esc - Exit
"""
print(menu_text)
finder = the_finder()
finder.run()