原地址:
https://alexene.dev/2019/06/02/Hierarchical-pathfinding.html
讲解视频:
https://www.youtube.com/watch?v=qSbSb8vMbLI
目标问题:
为不同的分割区建立door,也就是两个分割器有两个相邻的小格,这两个小格子是可以联通的,下图中指的是在黄色线两侧的相邻的两个蓝色小格子。
在每个划分后的格子里面(黄色线割出的大格子)设置好蓝色的door后,为大格子内的所有蓝色小格子建立连接,并得到彼此之间的连接路径的长度。注意,往往我们会在一个大格子的边缘上选几个点,而这里是将所有的边上的点(没有阻碍的点,不包括黑点)都设置为可以联通的点,比如一个10 * 10的大格子,我们一个边上有10个点,但是我们实际中并不会设置10个door,而是在这10个中选择几个,如三个点作为door。
在大格子中,10 * 10 的格子中,我们也是使用A* 算法建立出边缘点之间的连接路径的,因此如果边缘点上选择过多的作为door就会导致在为大格子计算内部路径时耗费过多的计算资源,因此我们可以选择大格子边缘上的几个点作为door。
我们知道了在大格子内部为边缘上的door建立路径,这时候使用的是A* 算法,我们需要把这个结果进行保存,在大格子之间进行寻路时依然使用A* 算法,这时我们选择哪个大格子作为下一步时是只选取之前保存的路径数值的。
Getting a path
Now that we have our high-level cells and they have connections between them and internal connections we just need to explore two things when we are searching for a path.
- From the starting point find all possible high-level connections that we can start from
- Traverse the high-level graph until we reach the high-level cell containing the destination.
- Once we reached that end high-level cell, do a low-level A* to find if from the entry point we have a path to the destination.
As our entity moves through the world it will encounter a cell that’s connected to another far away cell. This is for the case where we need to traverse a high-level cell. In that case we have to call A* pathfinding again for that high-level cell.
It is also possible to cache the path and just querry it as it saves us a A* search for a 10x10 cell. This is what I do and if you have spare memory to cache these paths I highly recommend doing so.
For example a path from the start point S to the destination D will look like this:
- The orange cells are part of low-level paths.
- The red cells are connected in the high-level pathfinding grid. For them we either have low-level paths cached or we compute them as needed. When we reach the first cell touched by that red arrow.
标签:cell,door,格子,level,high,blog,外网,Near,10 From: https://www.cnblogs.com/devilmaycry812839668/p/18170943