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

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

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


当前回答

假设你已经有了追逐吃豆人所需的逻辑,为什么不重用它呢?只要改变目标。这似乎比尝试使用完全相同的逻辑创建一个全新的例程要少得多。

其他回答

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

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

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


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

这是一个寻径问题。有关流行的算法,请参见http://wiki.gamedev.net/index.php/A*。

我认为你的解决方案是正确的,比这更简单,就是制作一个更“现实”的新版本,鬼魂的眼睛可以穿过墙壁=)

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

我不太清楚你是如何执行游戏的,但你可以这么做:

Determine the eyes location relative position to the gate. i.e. Is it left above? Right below? Then move the eyes opposite one of the two directions (such as make it move left if it is right of the gate, and below the gate) and check if there are and walls preventing you from doing so. If there are walls preventing you from doing so then make it move opposite the other direction (for example, if the coordinates of the eyes relative to the pin is right north and it was currently moving left but there is a wall in the way make it move south. Remember to keep checking each time to move to keep checking where the eyes are in relative to the gate and check to see when there is no latitudinal coordinate. i.e. it is only above the gate. In the case it is only above the gate move down if there is a wall, move either left or right and keep doing this number 1 - 4 until the eyes are in the den. I've never seen a dead end in Pacman this code will not account for dead ends. Also, I have included a solution to when the eyes would "wobble" between a wall that spans across the origin in my pseudocode.

一些伪代码:

   x = getRelativeOppositeLatitudinalCoord()
   y
   origX = x
    while(eyesNotInPen())
       x = getRelativeOppositeLatitudinalCoordofGate()
       y = getRelativeOppositeLongitudinalCoordofGate()
       if (getRelativeOppositeLatitudinalCoordofGate() == 0 && move(y) == false/*assume zero is neither left or right of the the gate and false means wall is in the way */)
            while (move(y) == false)
                 move(origX)
                 x = getRelativeOppositeLatitudinalCoordofGate()
        else if (move(x) == false) {
            move(y)
    endWhile