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

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

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


当前回答

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

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

其他回答

实际上,我想说你的方法是一个非常棒的解决方案,与任何类型的寻径相比,运行时间成本几乎为零。

如果你需要将其推广到任意地图,你可以使用任何寻径算法——例如,宽度优先搜索很容易实现——并在游戏运行前使用该算法计算在每个角落编码的方向。

编辑(2010年8月11日):我刚刚看到了关于吃豆人系统的一个非常详细的页面:the Pac-Man Dossier,既然我已经得到了公认的答案,我觉得我应该更新它。这篇文章似乎没有明确地涉及回到怪物房子的行为,但它指出了《吃豆人》中的直接寻路是以下情况:

继续向下一个路口移动(尽管这本质上是一种特殊情况,即“当有选择时,选择不涉及反转方向的方向,如下一步所示); 在十字路口,看看相邻的出口方块,除了你刚刚出来的那个; 选一个离目标最近的。如果有多个方向同样接近目标,则按以下顺序选择第一个有效方向:上、左、下、右。

Dtb23的建议是在每个角落随机选择一个方向,最终你会发现怪物洞听起来非常低效。

然而,你可以利用它低效的“回家”算法,通过在游戏难度中引入更多变化来让游戏变得更有趣。你可以通过应用上面的方法,比如你的路径点或洪水填充来做到这一点,但这样做是非确定性的。所以在每个角落,你都可以生成一个随机数来决定是走最优路线,还是随机方向。

随着玩家不断推进关卡,你将减少玩家选择随机方向的可能性。这将在关卡速度,幽灵速度,吃药丸暂停等之外为整体难度关卡添加另一个杠杆。你有更多的时间放松,而鬼魂只是无害的眼睛,但随着你的进步,时间会越来越短。

简而言之,不是很好。如果你改变了《吃豆人》迷宫,眼睛就不一定会回来。有些四处游荡的黑客就有这个问题。所以它依赖于一个合作迷宫。

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

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

知道吃豆人的路径是非随机的(例如,每个特定的关卡0-255,inky, blinky, pinky和clyde将在该关卡中工作完全相同的路径)。

我会选择这个,然后猜测有一些主路径围绕整个 迷宫是眼球物体的“返回路径”,当吃豆人吃掉幽灵时,它就在那里。