# Practical application of a * Algorithm in mobile phone corner Map

Source: Internet
Author: User
Tags benchmark

Practical application of a * Algorithm in mobile phone corner Map

I will not mention the basic implementation of the * algorithm here. There are many such articles for your reference. I am still a student Master Major in the J2EE direction. If not, please forgive me.
A * the key to implementing an algorithm in a diagonal map is to determine the benchmark for each movement. You can set the benchmark to be fine or rough. You can compare the two images below.

In my implementation, I chose the latter, that is, the rough set of the benchmark is set in the center of each tile. There are two reasons: 1. the computation is obviously simple and the speed will be much faster. 2. It is also convenient to identify obstacles. The previous method is usually used when the tracing accuracy is high. Of course, it is also very good to use both of them, that is, to use a rough path finding point on a large path, to use a precise path finding point on a target tile for calculation. I currently use this method:

As shown in, the start and end points of the pathfinding are not always in the tile center. If you want to use a * with rough precision, you must make the pathfinding point in the center. (currently, the mobile phone key only supports eight directions, path finding points are also required in the center ). We use this method to calculate every tile that a * is going through, and then change the starting point to the center of the second tile to move (that is, it is not a Direct Oblique direction, in this way, the path finding points are moved to the center, and the intermediate process can be moved Based on tile (the orange path in the figure ), to the second last tile, move it to the target point again. This allows you to move more accurately. Do not modify the movement in the first tile, because it may be the case that the center is under the person, and the trend of the * algorithm of the person is to move up, it is silly to move people down first and then up.
Some opinions:
1 The binary heap a * algorithm is not required in mobile phones.
About binary heap a * algorithm, you are interested to see this http://www.policyalmanac.org/games/binaryHeaps.htm
It is mainly used to optimize the Open table, but I don't think it is necessary to use it in mobile games. Let's take my implementation as an example. On the screen of 180*208, I pasted around 40 tile. We all know that monsters generally have visual vision. It is good to see more than one screen. In this case, there are already many (almost impossible) more than 40 nodes in open ), we use binary insert sorting to fully meet the performance requirements, without using binary heap. (This is one of the reasons why I use the rough precision path finding method :))

2 open tables and closed tables can use static internal classes to inherit the implementation of vector, and the performance will not be compromised.

Related Keywords:

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.