-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (60 loc) · 1.99 KB
/
main.py
File metadata and controls
76 lines (60 loc) · 1.99 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
"""
Main entry point for the Maze Solver application.
This script demonstrates how to use the DFS maze solver with example mazes.
"""
from maze import Maze
from dfs_solver import DFSSolver
from example_mazes import MAZE_EXAMPLES
def solve_and_display(maze_grid, maze_name):
"""
Solve a maze and display the results.
Args:
maze_grid: 2D list representing the maze
maze_name: Name of the maze for display purposes
"""
print(f"\n{'='*60}")
print(f"Solving: {maze_name.upper()} MAZE")
print(f"{'='*60}")
# Create maze object
maze = Maze(maze_grid)
print("\nOriginal Maze:")
maze.display()
# Create solver and solve
solver = DFSSolver(maze)
path = solver.solve()
# Display results
if path:
print(f"\n✓ Solution found!")
print(f"\nMaze with Solution Path (marked with *):")
maze.display(path)
# Display statistics
stats = solver.get_statistics()
print(f"\nStatistics:")
print(f" - Path length: {stats['path_length']} steps")
print(f" - Nodes visited: {stats['visited_nodes']}")
print(f" - Efficiency: {stats['efficiency']:.2%}")
else:
print(f"\n✗ No solution exists for this maze!")
def main():
"""
Main function to run the maze solver demonstrations.
"""
print("="*60)
print("DFS MAZE SOLVER - Educational Implementation")
print("="*60)
print("\nThis program demonstrates the Depth-First Search (DFS)")
print("algorithm for solving mazes.")
print("\nLegend:")
print(" S = Start position")
print(" E = End/Goal position")
print(" █ = Wall (impassable)")
print(" . = Open path")
print(" * = Solution path")
# Solve all example mazes
for name, maze_grid in MAZE_EXAMPLES.items():
solve_and_display(maze_grid, name)
print(f"\n{'='*60}")
print("All demonstrations complete!")
print(f"{'='*60}\n")
if __name__ == "__main__":
main()