大地图上的寻路 [英] Pathfinding on large map

查看:501
本文介绍了大地图上的寻路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建具有10,000 x 10,000地图的游戏。

我希望用户能够设置位置并让计算机立即找到最佳路径。

但是,由于映射是10,000 x 10,000,因此有100,000,000个节点,要通过常规方法(例如A *或Dijkstra's)找到此路径,将需要大量的内存和较长的时间。

所以我的问题是:如何找到最佳路径?

我正在考虑的算法会将世界分为100个部分,每个部分有1,000,000个节点。然后将每个部分分为100个子部分。将重复此操作,直到每个小节包含100个节点。然后,该算法将找到节,子节,子子节的最佳路径,直到找到最佳的节点集。

我也在考虑一个跳点搜索,但我不知道,要发现它会很痛苦。

I'm creating a game with a 10,000 by 10,000 map.
I would like for a user to be able to set a location and have the computer instantly find the best path.
However, since the map is 10,000 by 10,000, there are 100,000,000 nodes, and to find this path through a conventional method such as A* or Dijkstra's would require a large amount of memory and a long time.
So my question is: How can I find the best path?
The algorithm I'm considering would divide the world into 100 sections, each with 1,000,000 nodes. Each section would then be divided into 100 subsections. This would be repeated until each subsection contains 100 nodes. The algorithm would then find the best path of sections, then subsections, then sub-sub sections until it finds the best set of nodes. Would this work and is there a better way?
I'm also considering a jump-point search, but I don't know it, and it'd be a pain to learn just to find that it can't do it.

编辑:我试图添加A *。但是,它花费了大约5秒钟来运行,比理想运行时间长了约4秒钟。

I have attempted to add A*. However, it took about 5 seconds to run, which is about 4 seconds longer than ideal.

推荐答案

由于地图是10.000 x 10.000的节点数是100.000.000。使用A *的简单实现是不切实际的,并且肯定不会使游戏在mapsize中可缩放。

Since the map is 10.000 x 10.000 the number of nodes is 100.000.000. Using a straightforward implementation of A* would be impractical and certainly wouldn't make the game scalable in mapsize.

我建议您使用以下解决方案,该解决方案本质上是您的想法:

I would recommend you to use the following solution, which is essentially what you were thinking:

HPA * (分级路径A *)。此方法创建不同的地图层次结构。您可以说100x100像素的每个块都是一个区域,从而使该过程自动化。然后,对于每个块,我们需要找到相邻的块以及每个块的入口和出口在哪里。
如果两个块之间的连接超过一个节点,则我们使用两个节点来表示问题。此图片说明了我们要构建的新图形。 (黑色=障碍物和灰色在块之间连接节点)。

HPA* (Hierarchical Path A*). This method creates different hierarchies of map. You may automate the process by saying every block of 100x100 pixels is a region. Then, for every block, we need to find the adjacent blocks and where the entries and exits for each block is. If the connection between the two blocks is more than a node then we use two nodes to represent the problem. This image explains the new graph that we're trying to build. (Black=obstacle and grey are connecting nodes between blocks).

此方法可提供良好的效果,从使用Baldur's Gate游戏中的地图执行时可以看到,每个块均为10x10。

This method provides good results as can be seen from an execution using maps from the game Baldur's Gate with every block being 10x10.

有关更多信息,请阅读Nathan Sturtevant的这篇文章(他是游戏领域最成功的寻路研究员之一)。
https://skatgame.net/mburo/ps/path.pdf

For more information read this article from Nathan Sturtevant (he is one of the most succesful path-finding researcher when it comes to games). https://skatgame.net/mburo/ps/path.pdf

有关HPA的说明,请查看Sturtevant的讲座(HPA最低43:50)。
https://www.youtube.com/watch?v=BVd5f66U4Rw

For an explanation of HPA please check this lecture of Sturtevant (min 43:50 for HPA). https://www.youtube.com/watch?v=BVd5f66U4Rw

另外,如果您想查看HPA *的使用情况,请查看Sturtevant制作的以下视频:
https://www.youtube.com/watch?v=l7YQ5_Nbifo

Also, if you want to see HPA* in action check this video that Sturtevant made: https://www.youtube.com/watch?v=l7YQ5_Nbifo

这篇关于大地图上的寻路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆