Skip to content

Commit 5ef686d

Browse files
committed
added neighbor.cost to next g score calculation
1 parent f2475f1 commit 5ef686d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/finders/AStarFinder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ AStarFinder.prototype.findPath = function(startX, startY, endX, endY, grid) {
9595

9696
// get the distance between current node and the neighbor
9797
// and calculate the next g score
98-
ng = node.g + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
98+
ng = node.g + neighbor.cost + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
9999

100100
// check if the neighbor has not been inspected yet, or
101101
// can be reached with smaller cost from the current node

src/finders/BiAStarFinder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ BiAStarFinder.prototype.findPath = function(startX, startY, endX, endY, grid) {
103103

104104
// get the distance between current node and the neighbor
105105
// and calculate the next g score
106-
ng = node.g + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
106+
ng = node.g + neighbor.cost + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
107107

108108
// check if the neighbor has not been inspected yet, or
109109
// can be reached with smaller cost from the current node
@@ -147,7 +147,7 @@ BiAStarFinder.prototype.findPath = function(startX, startY, endX, endY, grid) {
147147

148148
// get the distance between current node and the neighbor
149149
// and calculate the next g score
150-
ng = node.g + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
150+
ng = node.g + neighbor.cost + ((x - node.x === 0 || y - node.y === 0) ? 1 : SQRT2);
151151

152152
// check if the neighbor has not been inspected yet, or
153153
// can be reached with smaller cost from the current node

0 commit comments

Comments
 (0)