简体   繁体   English

知识有限且无距离启发式的寻路

[英]Pathfinding with limited knowledge and no distance heuristic

I'm having trouble writing the pathfinding routine for the AI in a simple Elite-esque game I'm writing. 我在编写一个简单的精英式游戏中编写AI的寻路例程时遇到了麻烦。

The world in this game is a handful of "systems" connected by "wormholes", and a ship can jump from the system it's in to any system it's linked to once per turn. 该游戏中的世界是由“虫洞”连接的少数“系统”,一艘船每回合可以从其所在的系统跳至与其链接的任何系统。 The AI is limited to only knowing things that it should know; AI被限制为只知道它应该知道的事情; it doesn't know what links come from a system it hasn't been to (though it can work it out from the systems it has seen, since links are two-way). 它不知道什么链接来自从未访问过的系统(尽管它可以从它所看到的系统中解决,因为链接是双向的)。 Other parts of the AI decide which system the ship needs to get to based on what goods it has in its inventory and how much it remembers things being worth on systems it has passed through. AI的其他部分根据库存中所存的货物以及所经历的系统中值得记住的东西来决定船舶需要到达的系统。

The problem is, I don't know how to approach the problem of finding a path to the target system. 问题是,我不知道如何解决找到目标系统路径的问题。 I can't use A*; 我不能使用A *; there's no way to determine the 'distance' to another system without pathing to it. 没有路径,就无法确定与另一个系统的“距离”。 I also need this algorithm to be efficient, since it'll need to run about 100 times every time the player takes his turn. 我还需要这种算法高效,因为每次轮到玩家都需要运行约100次。

Does anyone know of a suitable algorithm? 有人知道合适的算法吗?

I ended up implementing a bidirectional, greedy version of breadth-first search, which suits the purpose well enough. 我最终实现了广度优先搜索的双向贪婪版本,该版本非常适合此目的。 To put it simply, I just had the program look through each node its starting node connected through, then each node those nodes connected to, then each node those connected to... until the destination node was found. 简而言之,我只是让程序查看通过其起始节点连接的每个节点,然后查看与之连接的每个节点,然后再与与之连接的每个节点...,直到找到目标节点。

Normally one would build a list of appropriate paths and pick the shortest one, but I tried a different method; 通常,人们会建立一列适当的路径并选择最短的路径,但是我尝试了另一种方法。 I had the program run two searches in parallel, one from the starting point, and one from the end point. 我让程序并行运行两次搜索,一次从起点开始,一次从终点开始。 When the 'from' search found the last node of the 'to' search, the path was considered found. 当“从”搜索找到“到”搜索的最后一个节点时,就认为该路径已找到。

It then optimizes the path by checking if each node on the path connects to a node further up in the path, and deleting each node in between them. 然后,它通过检查路径上的每个节点是否连接到路径中更远的节点,并删除它们之间的每个节点来优化路径。

Whether or not this funky algorithm is actually any better than a straight BFS remains to be seen. 这种时髦的算法实际上是否比纯BFS更好,还有待观察。

When it comess to unknown environments, I usually use an evolutionary algorithm approach. 对于未知环境,我通常使用进化算法方法。 It doesn't guarantee that you'll find the best solution in the small timeframe you have, but is a way to approach such a problem. 它不能保证您会在短时间内找到最佳解决方案,但这是解决此类问题的一种方法。

Have a look at Partially Observable Markov Decision Problems (POMDP). 看一下部分可观察的马尔可夫决策问题 (POMDP)。 You should be able to express your problem with this model. 您应该能够用此模型表达您的问题。

Then you can use an algorithm that solves these problems to try to find a good solution. 然后,您可以使用解决这些问题的算法来尝试找到一个好的解决方案。 Note that solving POMDPs is usually very expensive and you probably have to resort to approximate methods. 请注意,解决POMDP通常非常昂贵,您可能必须诉诸近似方法。

Easiest way to cheat this would be o go through, or at least attempt to access as many systems as possible, then implement the distance heuristic as the sum of all the systems you've been to. 作弊的最简单方法是o经历,或者至少尝试访问尽可能多的系统,然后将距离启发式方法实现为您去过的所有系统的总和。

Alternatively, and way cooler: 或者,更酷:

I've implemented something similar using ACO (Ant colony optimization) and worked pretty well combined with PSO(particle swarm optimization), however, the additional constraints your system is imposing means that you'll have to spend a few (at least one) sessions figuring out the environment layout, and if it's dynamic... well... though. 我已经使用ACO(蚁群优化)实现了类似的操作,并且与PSO(粒子群优化)结合使用时效果很好,但是,系统施加的其他限制意味着您必须花费一些(至少一个)会议确定环境布局,以及环境布局是否动态……嗯……不过。
The good thing is that this algorithm completely bypasses the need for heuristic generation which is what you need since you are flying blind. 好消息是,此算法完全绕开了启发式生成的需求,而这正是盲目飞行所需要的。 Be advised though, that this is a bad idea if your search space (number of runs) is small. 但请注意,如果您的搜索空间(运行次数)很小,这是个坏主意。 (100 may be acceptable, but 10 or 5 ... not so much). (100可以接受,但10或5 ...不太高)。

This scales up quite nicely when dealing with large numbers of nodes (systems) and it bypasses the heuristic distance computational need for every node-to-node relationship, thereby making it more efficient. 当处理大量节点(系统)时,这可以很好地扩展,并且绕过每个节点到节点关系的启发式距离计算需求,从而使其效率更高。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 允许的启发式曼哈顿距离 - Admissible Heuristic Manhattan Distance 改进的a-star寻路启发式设计 - Modified a-star pathfinding heuristic design 曼哈顿距离如何成为可接受的启发式方法? - How is Manhattan distance an admissible heuristic? 具有指定距离/节点数的寻路算法 - Pathfinding algorithm with specified distance/number of nodes 如何设计成本 function 和启发式 function 使用 A* 寻路算法找到 FASTEST 路线? - How to design a cost function and a heuristic function that finds the FASTEST route using an A* pathfinding algorithm? 如何在A *启发式中添加比仅距离更多的参数? - How to add more parameters to A* heuristic than only distance? 生成塔防迷宫(有限墙壁的最长迷宫) - 近乎最佳的启发式? - Generating a tower defense maze (longest maze with limited walls) - near-optimal heuristic? 使用启发式算法可以通过A *找到多少次优路径,而后者会高估剩余距离? - By how much suboptimal can be path found with A* using heuristic which overestimates the remaining distance a little? 爬山算法使用Levenshtein距离作为Python中的启发式生成一个字符串? - Hill-climbing algorithm to generate a string using Levenshtein distance as heuristic in Python? 启发式和A *算法 - Heuristic and A* algorithm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM