First, the mode of seeking road
1. Examples and explanations
(1) For example, when playing a game, select a target point, the character will automatically reach our designated target point
(2) Select the start and end point on the map and the map will automatically give us a more reasonable route (probably the nearest route)
2, three modes
(1) Depth-first search
A definition: Find the adjacent connection point from the starting point, and then continue to look for the next adjacent point from the adjacent point, always search to the target point
B Features: One layer to find the line, disadvantage: There is no way to find the best route
(2) Breadth First search
A definition: Spreading like a mesh, spreading from one point to the other, spreading from the next point around like
B Features: Large search area, low performance, to carry out a large number of calculations
(3) Heuristic search
The evaluation function is adopted to simulate the selection of this point.
A definition: Fully consistent with human thought and designed according to human thought
B Features: To ensure optimal path and performance
Third, the valuation function
(1) f (n) = g (n) + H (n)
F (n) is an estimate function of N-node
g (n) is the actual cost of the initial point to the N node
H (n) is the actual cost of N-node to target point
(2) A * algorithm program implementation
- Open Queue--sort valuation function
- Close queue--Exclude interference nodes
- Querying adjacent locations
- Package valuation function f () g () H ()
- Set the parent node pointer
(3)
JS algorithm and data structure