码迷,mamicode.com
首页 > 其他好文 > 详细

两层A *路径搜索之草译

时间:2015-06-18 07:08:00      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

A *路径搜索

Two-Tiered A* Pathfinding

 

作者:帕特里克·莱斯特(更新200319日)

By Patrick Lester ( Updated January 9, 2003)

 

在我的主文章A *路径搜索入门(http://my.oschina.net/u/660460/blog/467603)里,我非常笼统得描述了A*,并描述了如何建一个一的通用路径搜索功能。建只有一个路径搜索功能,但是,可以是不必要的限制。

In my main article, A* Pathfinding for Beginners, I described A* in very general terms, and described how to create a single all-purpose pathfinding function. Creating only one pathfinding function, however, can be needlessly limiting.

 

下面的RPG情况,想找到绕过附近的的路

Consider the following RPG situation, and a swordsman who wants to pathfind around a nearby wall:

 

技术分享


种地,可以以各种方式使用各种密度放置点。在个例子中,使用了高密度点网,如下所示。

Given this kind of map, you could place nodes in a variety of ways, and use a variety of densities. In this example, let‘s use a high-density node network, as is shown below.

 

技术分享

 

在此中,白点的能走的。没有点的地儿走。在个例子中我做一些有点不同事情。在个例子中,你被允抄近路方格。另外,“方格”本身不是方形了。因为这是一个等距例,我已决定了Y(垂直X(水平)两倍多点。适当的等距路径。

In this graphic, the white nodes are walkable. Spots where there are no nodes are unwalkable. We also do some things a little differently in this example. In this example you are allowed to "cut corners" around unwalkable squares. Also the "squares" themselves aren‘t square anymore. Because this is an isometric example, we have decided to pack twice as many nodes on the Y (vertical axis) as there are on the X (horizontal) axis. This allows proper isometric paths.

 

正如你所看到的,使用点的网,我可以在附近的找到路径,但也上和附近的桶的程之。我的密集点的网络路径搜索也可以的站立的火炬,其中在最基点是不走。之,是精密路径搜索

As you can see, using this tightly packed node network, we can pathfind not only around the nearby wall but also between the wall and the nearby barrel in the process. Our dense node network also allows pathfinding around the standing torch, where the node at the very base is unwalkable. This, in sum, is precision pathfinding.

 

是在短距离的情况下很酷,但我需要在整个地路径搜索?用密密麻麻的网络节点像这样很容易A *搜索通只是一个一的路径超过10,000以上个点。来几乎任何PC嘎然而止。

Well, that is pretty cool in short-distance situations, but what do we do if we need to pathfind across the entire map? Using a densely packed node network like this could easily leave you searching through 10,000+ nodes on just a single pass through the A* loop. That will bring just about any PC to a grinding halt.

 

所以,来看看另一种选择。如果我们选择创建一个更密集的点的网,就像一个你下文?

So let‘s look at an alternative. What if we chose to create a much less dense node network, like the one you see below?

 

技术分享

 

个例子中,点是在的大等距菱形的中心。关于菱形能走的数据存在沿边缘相同的数,并表示在形与色的小点。从一个等距瓦移到其相8相邻的砖块之一,相邻砖块本身必能走的,之的路径不能被阻止。

In this example, the nodes are in the center of the large isometric diamonds. Data about walkability between the diamonds is stored in the same array along the edges, and is represented in this graphic with small red dots. To move from one isometric tile to one of its 8 adjacent macro-tiles, the adjacent tile must itself be walkable, and the path between must not be blocked. 

 

点网是比早的一个不密集的72倍。相反,有多达10000理,在任何时间,在里我将只能与1/72的,或小于200。我算机理肯定可以搞定。整个地图路径搜索不再是一个问题

This node network is 72 times less dense than the earlier one. Instead of dealing with as many as 10,000+ nodes at any given time, here we will only be dealing with 1/72 of that, or less than 200. Our computer can definitely handle that. Pathfinding across the map is no longer a problem.

 

把两者合起来

Putting the Two Together

 

所以,我们选择哪种方法?两个

So, which method do we choose? Both!

 

在任何定的搜索,你会先pathfind整个地,用宏观层面探路。这样,你会切到微探路者和搜索从当前位置的路径点两种宏运点走的道路。一旦你入每一个新的宏观层面的菱形方格”,你会用微观层面来探路,以pathfind点两种宏运点提前。这结束了浪每个微通道的下半年,但你需要这样做,以确保它看起来不 - 是没有太大的浪,因你是跨越一个相短的距离微路径搜索。一旦你2-3离目,你会完全切到微探路者,并pathfind到最位置。

On any given search, you would first pathfind across the map, using the macro-level pathfinder. You would then switch to the micro-pathfinder and search for a path from the current location to the node two macro-nodes away on the path. Once you entered each new macro-level diamond "square," you would use the micro-level pathfinder to pathfind to the macro-node two macro nodes ahead. This ends up wasting the second half of each micro-path, but you need to do this to make sure it looks good -- and it isn‘t much of a waste, since you are micro-pathfinding across a relatively short distance. Once you get 2-3 macro nodes away from the target, you would switch over completely to the micro-pathfinder, and pathfind to the final location.

 

使用种方法,你会得到快速路径搜索整个地,能够进微知著,桶等,以现实的方式,因在早期的微路径搜索的例子。很酷,呵呵!

Using this approach, you will get speed pathfinding across the entire map and be able to negotiate around corners, barrels, etc. in a realistic way, as in the earlier micro-pathfinding example. Pretty cool, huh!

 

如果你是*真的*雄心勃勃,你可以开3探路者,如果你有一个非常大的地,一个在一个真正宏观层面,一是中等水平,以及一个微观层面。像帝国代游戏那样的专业人士做到了一点。只是取决于你的需求是什么。

And if you are *really* ambitious, you could develop three pathfinders if you have a really big map, one at a really macro level, one medium level, and one micro-level. The professionals have done this for games like Age of Empires. It just depends on what your needs are.

 

,就是这样。与往常一联系到我:

Well, that‘s it. As always, I can be reached at:

 

pwlester@policyalmanac.org

 

在此之前,祝你好运!

Until then, good luck!

 

两层A *路径搜索之草译

标签:

原文地址:http://my.oschina.net/u/660460/blog/468167

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!