Skip to content

Commit 3d14fb6

Browse files
committed
Merge branch 'master' into develop
2 parents e95c507 + 79ad4db commit 3d14fb6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

include/astar.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ namespace alg {
8686
// The map of navigated nodes.
8787
HashTable<uint32_t, uint32_t> came_from(nrow*ncol);
8888

89-
g_score(x1,y1) = 0.0f;
90-
f_score(x1,y1) = g_score(x1,y1) + estimate(x1,y1,x2,y2);
89+
g_score(y1,x1) = 0.0f;
90+
f_score(y1,x1) = g_score(y1,x1) + estimate(x1,y1,x2,y2);
9191

9292
AStarResult * as = new AStarResult;
9393
as->path = NULL;
@@ -117,7 +117,7 @@ namespace alg {
117117
}
118118

119119
openset.delete_min();
120-
m_closedset(cx, cy) = true;
120+
m_closedset(cy, cx) = true;
121121

122122
// for each neighbor
123123
int nx, ny;
@@ -127,26 +127,26 @@ namespace alg {
127127
if (ny<0 || ny>=(int)nrow) continue;
128128

129129
// except the wall;
130-
if(m_grid(nx,ny) == WALL) continue;
130+
if(m_grid(ny,nx) == WALL) continue;
131131
// except the cur itself
132132
if(nx == cx && ny==cy) continue;
133133
// if neighbour in the closed set
134-
if(m_closedset(nx,ny)) continue;
134+
if(m_closedset(ny,nx)) continue;
135135

136-
float tentative = g_score(cx,cy);
136+
float tentative = g_score(cy,cx);
137137
if (nx == cx || ny == cy) {
138-
tentative += 1;
138+
tentative += 1 + m_grid(ny,nx);
139139
} else {
140-
tentative += SQRT2;
140+
tentative += (1 + m_grid(ny,nx)) * SQRT2;
141141
}
142142

143143
// if neighbour not in the openset or dist < g_score[neighbour]
144-
if (!openset.contains(nx*ncol+ny) || tentative < g_score(nx,ny)) {
144+
if (!openset.contains(nx*ncol+ny) || tentative < g_score(ny,nx)) {
145145
came_from[nx*ncol+ny] = cx*ncol+cy; // record path
146-
g_score(nx,ny) = tentative;
147-
f_score(nx,ny) = tentative + estimate(nx,ny,x2,y2);
146+
g_score(ny,nx) = tentative;
147+
f_score(ny,nx) = tentative + estimate(nx,ny,x2,y2);
148148
if (!openset.contains(nx*ncol+ny)) {
149-
openset.insert(f_score(nx,ny), nx*ncol+ny);
149+
openset.insert(f_score(ny,nx), nx*ncol+ny);
150150
}
151151
}
152152
}

0 commit comments

Comments
 (0)