7
7
8
8
9
9
class Cell :
10
- def __init__ (self )-> None :
11
- # Parent cell's row index
10
+ def __init__ (self ) -> None :
11
+ # Parent cell's row index
12
12
self .parent_i = 0
13
13
# Parent cell's column index
14
14
self .parent_j = 0
@@ -86,7 +86,9 @@ def trace_path(cell_details: List[List[Cell]], dest: Tuple[int, int]) -> None:
86
86
# Implement the A* search algorithm
87
87
88
88
89
- def a_star_search (grid : List [List [int ]], src : Tuple [int , int ], dest : Tuple [int , int ]) -> None :
89
+ def a_star_search (
90
+ grid : List [List [int ]], src : Tuple [int , int ], dest : Tuple [int , int ]
91
+ ) -> None :
90
92
# Check if the source and destination are valid
91
93
if not is_valid (src [0 ], src [1 ]) or not is_valid (dest [0 ], dest [1 ]):
92
94
print ("Source or destination is invalid" )
@@ -204,8 +206,8 @@ def main() -> None:
204
206
Examples:
205
207
>>> main()
206
208
The destination cell is found
207
- The Path is
208
- -> (8, 0) -> (7, 1) -> (6, 0) -> (5, 1) -> (4, 0) -> (3, 1) -> (2, 0) -> (1, 1) -> (0, 0)
209
+ The Path is
210
+ -> (8, 0) -> (7, 1) -> (6, 0) -> (5, 1) -> (4, 0) -> (3, 1) -> (2, 0) -> (1, 1) -> (0, 0)
209
211
"""
210
212
# Define the grid (1 for unblocked, 0 for blocked)
211
213
grid = [
@@ -227,6 +229,6 @@ def main() -> None:
227
229
# Run the A* search algorithm
228
230
a_star_search (grid , src , dest )
229
231
232
+
230
233
if __name__ == "__main__" :
231
234
main ()
232
-
0 commit comments