# C # development Wpf/silverlight animation and games series Tutorials (Game Course): (vii)

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and game series Tutorials (Game Course): (vii) The legendary A * search path algorithm

There are two areas of knowledge about map engine processing:

1 The realization of the map (including map cutting, synthesis, presentation methods, etc.)

2 The realization of the Map object (including the map to achieve the path, mask, transmission point, etc.)

In order to make people more interested in the knowledge behind, I choose to start from the map to explain the road:

The most classic way to find a road in the game is a * (Star), it is a collection of road-seeking thinking, then there are a variety of algorithms based on it, such as the Manhattan heuristic algorithm, the diagonal path algorithm, Euclidean geometry algorithm, the maximum value algorithm, etc. Different algorithms produce different effects: such as calculating the total time required for the path, the length of the path obtained, and so on, and the different parameters will lead to a great difference in results. I draw on a * * * seek tool from a foreign cow (a friend who is interested can be in http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c12527/ To find the relevant resources, respectively, through a variety of paths using a variety of a * algorithm to find the path, and finally through the cost of time and path of the graceful comparison of the horizontal and vertical comparisons scored, get the fastest speed algorithm: Manhattan heuristic algorithm. It is able to perform exceptionally well in all of the complex path calculations, including even Jiuqu 18 bends, and the following illustration shows a partial screenshot of the test:

The brown lattice represents the obstacle, the starting point is in the upper left corner, the end is in the middle of the red border lattice, the blue lattice represents the found path. As you can see from the lower-right corner of the diagram, it is extremely good to find the best path in 3 milliseconds even in such a complex and branching maze. So many friends see that this may feel so complicated program, which is the average person can write it? In fact, it is difficult to say that there are some difficulties, but fortunately, our compatriots have already translated an introductory article, I looked very good, the translation of the article address is as follows (see this article please have patience not short, but after reading will have a very big harvest!) : http://data.gameres.com/message.asp?TopicID=25439, so how do we implement the Manhattan * with C # code? I start with a simple principle to describe: from the beginning of the divergence of the search around 8 points, through various conditions screen to select the best point, and then again as a starting point to continue to loop the above process, and finally we get all the starting set is the final path. Do you think it's not too hard? Oh, then everyone write it! (Everyone can refer to the foreign cow I give you write the program, which has the source code, through the reference source, I believe that we spend some time completely can easily realize their own a *)

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.