10
10
TEST_GRIDS = [
11
11
[
12
12
[0 , 0 , 0 , 0 , 0 , 0 , 0 ],
13
- [0 , 1 , 0 , 0 , 0 , 0 , 0 ],
13
+ [0 , 1 , 0 , 0 , 0 , 0 , 0 ],
14
14
[0 , 0 , 0 , 0 , 0 , 0 , 0 ],
15
15
[0 , 0 , 1 , 0 , 0 , 0 , 0 ],
16
16
[1 , 0 , 1 , 0 , 0 , 0 , 0 ],
23
23
[0 , 0 , 0 , 1 , 1 , 0 , 0 ],
24
24
[0 , 1 , 0 , 0 , 1 , 0 , 0 ],
25
25
[1 , 0 , 0 , 1 , 1 , 0 , 1 ],
26
- [0 , 0 , 0 , 0 , 0 , 0 , 0 ]
26
+ [0 , 0 , 0 , 0 , 0 , 0 , 0 ],
27
27
],
28
28
[
29
29
[0 , 0 , 1 , 0 , 0 ],
30
30
[0 , 1 , 0 , 0 , 0 ],
31
31
[0 , 0 , 1 , 0 , 1 ],
32
32
[1 , 0 , 0 , 1 , 1 ],
33
- [0 , 0 , 0 , 0 , 0 ]
34
- ]
35
- ]
33
+ [0 , 0 , 0 , 0 , 0 ],
34
+ ],
35
+ ]
36
36
37
37
delta = ([- 1 , 0 ], [0 , - 1 ], [1 , 0 ], [0 , 1 ]) # up, left, down, right
38
38
@@ -82,7 +82,7 @@ def calculate_heuristic(self) -> float:
82
82
83
83
def __lt__ (self , other ) -> bool :
84
84
return self .f_cost < other .f_cost
85
-
85
+
86
86
def __eq__ (self , other ):
87
87
return self .pos == other .pos
88
88
@@ -104,7 +104,9 @@ class GreedyBestFirst:
104
104
(4, 4)]
105
105
"""
106
106
107
- def __init__ (self , grid : list [list [int ]], start : tuple [int , int ], goal : tuple [int , int ]):
107
+ def __init__ (
108
+ self , grid : list [list [int ]], start : tuple [int , int ], goal : tuple [int , int ]
109
+ ):
108
110
self .grid = grid
109
111
self .start = Node (start [1 ], start [0 ], goal [1 ], goal [0 ], 0 , None )
110
112
self .target = Node (goal [1 ], goal [0 ], goal [1 ], goal [0 ], 99999 , None )
@@ -151,10 +153,11 @@ def get_successors(self, parent: Node) -> list[Node]:
151
153
pos_x = parent .pos_x + action [1 ]
152
154
pos_y = parent .pos_y + action [0 ]
153
155
154
- if (0 <= pos_x <= len (self .grid [0 ]) - 1
156
+ if (
157
+ 0 <= pos_x <= len (self .grid [0 ]) - 1
155
158
and 0 <= pos_y <= len (self .grid ) - 1
156
- and self .grid [pos_y ][pos_x ] == 0 ):
157
-
159
+ and self .grid [pos_y ][pos_x ] == 0
160
+ ):
158
161
successors .append (
159
162
Node (
160
163
pos_x ,
0 commit comments