JS algorithm and data structure

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.