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 *)