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

后端 未结 22 1791
南方客
南方客 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:06

    Here's an analog and pseudocode to ammoQ's flood fill idea.

    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
    

    The idea is that it's a breadth-first search, so each time you encounter a new adjacent square s, the best path is through p. It's O(N) I do believe.

提交回复
热议问题