File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 1
1
import heapq
2
2
import random
3
3
4
+
4
5
class MazeSolver :
5
6
def __init__ (self , maze ):
6
7
self .maze = maze
@@ -51,18 +52,22 @@ def solve(self):
51
52
52
53
if neighbor not in g_score or tentative_g_score < g_score [neighbor ]:
53
54
g_score [neighbor ] = tentative_g_score
54
- f_score [neighbor ] = tentative_g_score + self .heuristic (neighbor )
55
+ f_score [neighbor ] = tentative_g_score + \
56
+ self .heuristic (neighbor )
55
57
heapq .heappush (open_set , (f_score [neighbor ], neighbor ))
56
58
57
59
return None
58
60
61
+
59
62
def generate_random_maze (rows , cols , obstacle_probability ):
60
63
return [[random .random () < obstacle_probability for _ in range (cols )] for _ in range (rows )]
61
64
65
+
62
66
def print_maze (maze ):
63
67
for row in maze :
64
68
print ("" .join (["#" if cell else " " for cell in row ]))
65
69
70
+
66
71
def main ():
67
72
rows = 10
68
73
cols = 10
@@ -83,5 +88,6 @@ def main():
83
88
else :
84
89
print ("\n No path found!" )
85
90
91
+
86
92
if __name__ == "__main__" :
87
93
main ()
You can’t perform that action at this time.
0 commit comments