@@ -25,8 +25,8 @@ def build_nodes(width, height, matrix=None, inverse=False):
2525 # while others will be obstacles
2626 # if inverse is False, otherwise
2727 # it changes
28- weight = int (matrix [y ][x ]) if use_matrix else 1
29- walkable = weight <= 0 if inverse else weight >= 1
28+ weight = float (matrix [y ][x ]) if use_matrix else 1
29+ walkable = weight <= 0 if inverse else weight != 0
3030
3131 nodes [y ].append (Node (x = x , y = y , walkable = walkable , weight = weight ))
3232 return nodes
@@ -42,8 +42,8 @@ def __init__(self, width=0, height=0, matrix=None, inverse=False):
4242 self .passable_left_right_border = False
4343 self .passable_up_down_border = False
4444 if isinstance (matrix , (tuple , list )) or (
45- USE_NUMPY and isinstance (matrix , np .ndarray ) and
46- matrix .size > 0 ):
45+ USE_NUMPY and isinstance (matrix , np .ndarray )
46+ and matrix .size > 0 ):
4747 self .height = len (matrix )
4848 self .width = self .width = len (matrix [0 ]) if self .height > 0 else 0
4949 if self .width > 0 and self .height > 0 :
@@ -58,17 +58,17 @@ def set_passable_up_down_border(self):
5858 self .passable_up_down_border = True
5959
6060 def node (self , x , y ):
61- """
62- get node at position
61+ """Get node at position.
62+
6363 :param x: x pos
6464 :param y: y pos
6565 :return:
6666 """
6767 return self .nodes [y ][x ]
6868
6969 def inside (self , x , y ):
70- """
71- check, if field position is inside map
70+ """Check, if field position is inside map.
71+
7272 :param x: x pos
7373 :param y: y pos
7474 :return:
@@ -82,9 +82,9 @@ def walkable(self, x, y):
8282 return self .inside (x , y ) and self .nodes [y ][x ].walkable
8383
8484 def neighbors (self , node , diagonal_movement = DiagonalMovement .never ):
85- """
86- get all neighbors of one node
87- :param node: node
85+ """Get all neighbors of one node.
86+
87+ :param node: current node that we like to get the neighbors of.
8888 """
8989 x = node .x
9090 y = node .y
@@ -171,8 +171,7 @@ def grid_str(self, path=None, start=None, end=None,
171171 border = True , start_chr = 's' , end_chr = 'e' ,
172172 path_chr = 'x' , empty_chr = ' ' , block_chr = '#' ,
173173 show_weight = False ):
174- """
175- create a printable string from the grid using ASCII characters
174+ """Create a printable string from the grid using ASCII characters.
176175
177176 :param path: list of nodes that show the path
178177 :param start: start node
@@ -202,7 +201,12 @@ def grid_str(self, path=None, start=None, end=None,
202201 line += path_chr
203202 elif node .walkable :
204203 # empty field
205- weight = str (node .weight ) if node .weight < 10 else '+'
204+ if node .weight > 10 :
205+ weight = '+' # weight bigger than 10
206+ elif node .weight < 1 and node .weight > 0 :
207+ weight = '-' # weight between 0 and 1
208+ else :
209+ weight = str (int (node .weight ))
206210 line += weight if show_weight else empty_chr
207211 else :
208212 line += block_chr # blocked field
0 commit comments