Skip to content

Commit 648aca7

Browse files
author
xtaci
committed
fix a bug in astar algorithm
1 parent dbee129 commit 648aca7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/astar.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ namespace alg
135135
if(nx == cx && ny==cy) continue;
136136
// if neighbour in the closed set
137137
if(m_closedset(nx,ny)) continue;
138-
139-
float tentative = g_score(cx,cy) + SQRT2;
138+
139+
float tentative = g_score(cx,cy);
140+
if (nx == cx || ny == cy) {
141+
tentative += 1;
142+
} else {
143+
tentative += SQRT2;
144+
}
140145

141146
// if neighbour not in the openset or dist < g_score[neighbour]
142147
if (!openset.contains(nx*ncol+ny) || tentative < g_score(nx,ny)) {

0 commit comments

Comments
 (0)