Pacman: how do the eyes find their way back to the monster hole?

后端 未结 22 1785
南方客
南方客 2021-01-29 17:53

I found a lot of references to the AI of the ghosts in Pacman, but none of them mentioned how the eyes find their way back to the central ghost hole after a ghost is eaten by Pa

22条回答
  •  [愿得一人]
    2021-01-29 18:02

    I don't know much on how you implemented your game but, you could do the following:

    1. Determine the eyes location relative position to the gate. i.e. Is it left above? Right below?
    2. 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.
    3. 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.
    4. 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.
    5. 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.
    6. I've never seen a dead end in Pacman this code will not account for dead ends.
    7. Also, I have included a solution to when the eyes would "wobble" between a wall that spans across the origin in my pseudocode.

    Some 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
    

提交回复
热议问题