@@ -25,12 +25,12 @@ def build_nodes(
2525 for x in range (width ):
2626 # 0, '0', False will be obstacles
2727 # all other values mark walkable cells.
28- # you can use values bigger then 1 to assign a weight.
28+ # you can use values bigger then 0 to assign a weight.
2929 # If inverse is False it changes
3030 # (1 and up becomes obstacle and 0 or everything negative marks a
3131 # free cells)
32- weight = int (matrix [y ][x ]) if use_matrix else 1
33- walkable = weight <= 0 if inverse else weight >= 1
32+ weight = float (matrix [y ][x ]) if use_matrix else 1
33+ walkable = weight <= 0.0 if inverse else weight > 0
3434
3535 nodes [y ].append (GridNode (
3636 x = x , y = y , walkable = walkable , weight = weight , grid_id = grid_id ))
@@ -121,9 +121,6 @@ def neighbors(
121121 neighbors = []
122122 north = nw = east = ne = south = se = west = sw = False
123123
124- lr = self .passable_left_right_border
125- ud = self .passable_up_down_border
126-
127124 # ↑
128125 if y == 0 and self .passable_up_down_border :
129126 north_y = self .height - 1
@@ -143,7 +140,7 @@ def neighbors(
143140 if self .walkable (east_x , y ):
144141 neighbors .append (self .nodes [y ][east_x ])
145142 east = True
146-
143+
147144 # ↓
148145 if y == self .height - 1 and self .passable_up_down_border :
149146 south_y = 0
@@ -207,7 +204,7 @@ def neighbors(
207204 ne_y = y - 1
208205 if self .walkable (ne_x , ne_y ):
209206 neighbors .append (self .nodes [ne_y ][ne_x ])
210-
207+
211208 # ↘
212209 if se :
213210 if x == self .width - 1 and self .passable_left_right_border :
@@ -273,9 +270,9 @@ def grid_str(self, path=None, start=None, end=None,
273270 data = ''
274271 if border :
275272 data = f'+{ "-" * len (self .nodes [0 ])} +'
276- for y in range ( len ( self .nodes ) ):
273+ for y , _ in enumerate ( self .nodes ):
277274 line = ''
278- for x in range ( len ( self .nodes [y ]) ):
275+ for x , _ in enumerate ( self .nodes [y ]):
279276 node = self .nodes [y ][x ]
280277 if node == start :
281278 line += start_chr
0 commit comments