@@ -86,8 +86,8 @@ namespace alg {
86
86
// The map of navigated nodes.
87
87
HashTable<uint32_t , uint32_t > came_from (nrow*ncol);
88
88
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);
91
91
92
92
AStarResult * as = new AStarResult;
93
93
as->path = NULL ;
@@ -117,7 +117,7 @@ namespace alg {
117
117
}
118
118
119
119
openset.delete_min ();
120
- m_closedset (cx, cy ) = true ;
120
+ m_closedset (cy, cx ) = true ;
121
121
122
122
// for each neighbor
123
123
int nx, ny;
@@ -127,26 +127,26 @@ namespace alg {
127
127
if (ny<0 || ny>=(int )nrow) continue ;
128
128
129
129
// except the wall;
130
- if (m_grid (nx,ny ) == WALL) continue ;
130
+ if (m_grid (ny,nx ) == WALL) continue ;
131
131
// except the cur itself
132
132
if (nx == cx && ny==cy) continue ;
133
133
// if neighbour in the closed set
134
- if (m_closedset (nx,ny )) continue ;
134
+ if (m_closedset (ny,nx )) continue ;
135
135
136
- float tentative = g_score (cx,cy );
136
+ float tentative = g_score (cy,cx );
137
137
if (nx == cx || ny == cy) {
138
- tentative += 1 ;
138
+ tentative += 1 + m_grid (ny,nx) ;
139
139
} else {
140
- tentative += SQRT2;
140
+ tentative += ( 1 + m_grid (ny,nx)) * SQRT2;
141
141
}
142
142
143
143
// 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 )) {
145
145
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);
148
148
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);
150
150
}
151
151
}
152
152
}
0 commit comments