-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_mazes.py
More file actions
105 lines (88 loc) · 2.42 KB
/
example_mazes.py
File metadata and controls
105 lines (88 loc) · 2.42 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
Example mazes for testing and learning.
This module provides pre-defined mazes of varying difficulty levels
for testing the DFS solver and learning purposes.
"""
def get_simple_maze():
"""
Returns a simple 5x5 maze - great for beginners.
Layout:
S . . . .
█ █ █ █ .
. . . . .
. █ █ █ █
. . . . E
"""
return [
['S', 0, 0, 0, 0],
[1, 1, 1, 1, 0],
[0, 0, 0, 0, 0],
[0, 1, 1, 1, 1],
[0, 0, 0, 0, 'E']
]
def get_medium_maze():
"""
Returns a medium complexity 8x8 maze.
This maze has multiple dead ends and requires backtracking.
"""
return [
['S', 0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 1, 0, 1, 0],
[1, 0, 0, 0, 1, 0, 0, 0],
[1, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0, 'E']
]
def get_complex_maze():
"""
Returns a complex 10x10 maze with many dead ends.
This maze demonstrates DFS backtracking behavior well.
"""
return [
['S', 0, 0, 1, 0, 0, 0, 0, 1, 0],
[1, 1, 0, 1, 0, 1, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 0, 'E']
]
def get_spiral_maze():
"""
Returns a spiral-shaped maze - interesting for visualization.
This maze creates a spiral path from start to end.
"""
return [
['S', 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 'E']
]
def get_impossible_maze():
"""
Returns an unsolvable maze - demonstrates that DFS correctly
identifies when no solution exists.
"""
return [
['S', 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[1, 1, 1, 1, 1],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 'E']
]
# Dictionary for easy access to all mazes
MAZE_EXAMPLES = {
'simple': get_simple_maze(),
'medium': get_medium_maze(),
'complex': get_complex_maze(),
'spiral': get_spiral_maze(),
'impossible': get_impossible_maze()
}