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 11import heapq
22import random
33
4+
45class MazeSolver :
56 def __init__ (self , maze ):
67 self .maze = maze
@@ -51,18 +52,22 @@ def solve(self):
5152
5253 if neighbor not in g_score or tentative_g_score < g_score [neighbor ]:
5354 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 )
5557 heapq .heappush (open_set , (f_score [neighbor ], neighbor ))
5658
5759 return None
5860
61+
5962def generate_random_maze (rows , cols , obstacle_probability ):
6063 return [[random .random () < obstacle_probability for _ in range (cols )] for _ in range (rows )]
6164
65+
6266def print_maze (maze ):
6367 for row in maze :
6468 print ("" .join (["#" if cell else " " for cell in row ]))
6569
70+
6671def main ():
6772 rows = 10
6873 cols = 10
@@ -83,5 +88,6 @@ def main():
8388 else :
8489 print ("\n No path found!" )
8590
91+
8692if __name__ == "__main__" :
8793 main ()
You can’t perform that action at this time.
0 commit comments