A * algorithm implementation steps

 

Core equation: F = G + H

The total cost of moving the box - F

G - the cost of moving to the start point of the current block (Development: G = the cost of moving the cost factor *)

H - the current square to the end point of the estimated cost of moving (that is, the Manhattan distance to this point to the end point)

A star algorithm also need to use two lists:

Open list - to record all of the lattice can consider options

Closed list - used to record all the grid is no longer considered

Advance wayfinding area is divided into several grids, included representatives of the obstacle grid, in determining the starting point of pathfinding, the end point of the case, assuming that each box has an F value that represents the current choose to go the route under consideration for the box.

A star pathfinding while the idea is simple: from the starting point, every step of the grid to select the minimum cost to go until it reaches the end point.

 

A star algorithm pseudo-code:

a, the recording start point to the current point P

b, the current point P to the closed list

C, searching for points near the point P, if neither a point adjacent the open or closed list which lists, the calculated value of the neighboring point F, and the parent node set P, then placed in the open list

d, to determine whether the open list is empty, if there is no explanation before reaching the end point has been done to find all possible paths point, pathfinding fails, the algorithm is finished; otherwise continue.

E, F come up with a minimum value of a point from the open list, as the next step in the path pathfinding.

f, to determine whether the point is the end point, and if so, to find the road to success, the end of the algorithm; otherwise continue.

g, the current point is set to point P, jump back to step c.

Guess you like

Origin www.cnblogs.com/wangqijun/p/11700026.html