我发现在《吃豆人》中有很多关于幽灵AI的参考,但没有一个提到当幽灵被《吃豆人》吃掉后,眼睛是如何找到中央幽灵洞的。

在我的实现中,我实现了一个简单但糟糕的解决方案。我只是在每个角落都用硬编码标明了应该往哪个方向走。

有没有更好的/最好的解决办法?也许是适用于不同关卡设计的通用设计?


当前回答

在游戏开始前保存地图上的节点(交叉点) 当怪物死亡时,取点(坐标)并找到 节点列表中最近的节点 计算从该节点到洞的所有路径 按长度取最短路径 将该点与最近节点之间的空间长度相加 绘制并在路径上移动

享受吧!

其他回答

我用这种方法解决了一般关卡的这个问题:在关卡开始前,我从怪物洞中进行某种“洪水填充”;迷宫中除了墙之外的每一块瓦都有一个数字,表示它离洞有多远。所以当眼睛盯着一个距离为68的瓦片时,他们会看哪个相邻的瓦片距离为67;那就这么办吧。

对于更传统的寻路算法的替代方案,您可以看看(名称很合适!)吃豆人气味反对象模式。

你可以在启动时在迷宫中弥漫怪物洞的气味,然后让眼睛跟着它回家。

气味设置好后,运行成本非常低。


编辑:很遗憾维基百科上的文章已经被删除了,所以WayBack Machine来拯救…

最初的《吃豆人》并没有使用寻径或花哨的AI。它只是让玩家觉得游戏比实际更有深度,但实际上它是随机的。正如Ian Millington和John Funge在《ai Intelligence for Games》中所述。

Not sure if it's true or not, but it makes a lot of sense to me. Honestly, I don't see these behaviors that people are talking about. Red/Blinky for ex is not following the player at all times, as they say. Nobody seems to be consistently following the player, on purpose. The chance that they will follow you looks random to me. And it's just very tempting to see behavior in randomness, especially when the chances of getting chased are very high, with 4 enemies and very limited turning options, in a small space. At least in its initial implementation, the game was extremely simple. Check out the book, it's in one of the first chapters.

下面是ammoQ的洪水填充想法的模拟和伪代码。

queue q
enqueue q, ghost_origin
set visited

while q has squares
   p <= dequeue q
   for each square s adjacent to p
      if ( s not in visited ) then
         add s to visited
         s.returndirection <= direction from s to p
         enqueue q, s
      end if
   next
 next

它的思想是宽度优先搜索,所以每次你遇到一个新的相邻正方形s,最好的路径是经过p。我相信是O(N)。

如果每个正方形都有一个到中心的距离值呢?这样,对于每个给定的正方形,你可以在所有可能的方向上得到相邻正方形的值。你选择最小值的正方形,然后移动到那个正方形。

数值将使用任何可用的算法预先计算出来。