Skip to content

Commit 8248786

Browse files
authored
Fixed calc_cost, was incorrectly calculating costs
1 parent 8751269 commit 8248786

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

pathfinding/finder/finder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ def calc_cost(self, node_a, node_b):
5858
"""
5959
get the distance between current node and the neighbor (cost)
6060
"""
61-
ng = node_a.g
6261
if node_b.x - node_a.x == 0 or node_b.y - node_a.y == 0:
6362
# direct neighbor - distance is 1
64-
ng += 1
63+
ng = 1
6564
else:
6665
# not a direct neighbor - diagonal movement
67-
ng += SQRT2
66+
ng = SQRT2
6867

6968
# weight for weighted algorithms
7069
if self.weighted:
7170
ng *= node_b.weight
7271

73-
return ng
72+
return node_a.g + ng
7473

7574
def apply_heuristic(self, node_a, node_b, heuristic=None):
7675
"""

0 commit comments

Comments
 (0)