Introduction to A * pathfinding algorithm (iv)

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Disclaimer: All translations provided by this blog are from the Internet and are for learning and communication purposes only. Also, do not remove this statement when reproduced. In case of any dispute, there is no relationship between the blogger and the person who published the translation. Thank you for your cooperation!

Path scoring

We will give each square a score of G + H:

    • G is the move cost from the start point A to the current block. So for a neighbor block that starts at point A, the value is 1, but the farther away from the start point, the greater the value.
    • H is the current block to the destination block (we call this point as a point with a bone b!) Estimated move cost, which is often called heuristic algorithm, because we don't really know how much it costs-it's just an estimate.

You may be surprised by the meaning of "mobile spending". In this game it is very simple-the number of blocks (via).

In any case, remember that you can make our game different. For example:

    • If you allow diagonal movement, you may set the cost of the diagonal move a bit higher.
    • If you have different terrains, you may be able to set them differently by spending them--for a chestnut: swamp, water or a poster of a cat girl;-)

That's the general idea-now we'll look further at how to calculate the values of G and H.

More about G

Recall that G is the cost of moving from the start point A to the current block (in this game, the number of blocks passed).

To calculate g, we need to take out the g of its parent square (which represents where we came from) and add 1. Therefore, the G value of each block represents the total cost from point A to the general path of its own block.

With a chestnut, a piece shows 2 different paths to 2 different bones, and the G value of each block is listed in the BLOCK:

More about H

Recall the following, H is the estimated mobile cost of the current block to the destination (in our game, that is, the number of squares passing through).

It is estimated that the closer the move is to the actual cost, the more accurate the final path will be. If the estimate is biased, the resulting path will not be the shortest (but may still be close). This topic is a bit complicated, so we won't go into the details in this series, but I'll provide a link to the article at the end. It explains very well.

In short, we will use the "Manhattan Distance Approach" (also known as "Manhattan Length" or "Block Distance"), which only calculates the number of squares that reach the horizontal and vertical point B, but does not take into account any obstructions or different terrains.

For a chestnut, here is a picture showing the use of "block distance" to estimate the H value from a different starting position to a destination (shown in an empty space):

Introduction to A * pathfinding algorithm (iv)

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.