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

后端 未结 22 1789
南方客
南方客 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:03
    1. Before the game begins save the nodes (intersections) in the map
    2. When the monster dies take the point (coordinates) and find the nearest node in your node list
    3. Calculate all the paths beginning from that node to the hole
    4. Take the shortest path by length
    5. Add the length of the space between the point and the nearest node
    6. Draw and move on the path

    Enjoy!

    0 讨论(0)
  • 2021-01-29 18:06

    Any simple solution that works is maintainable, reliable and performs well enough is a good solution. It sounds to me like you have already found a good solution ...

    An path-finding solution is likely to be more complicated than your current solution, and hence more likely to require debugging. It will probably also be slower.

    IMO, if it ain't broken, don't fix it.

    EDIT

    IMO, if the maze is fixed then your current solution is good / elegant code. Don't make the mistake of equating "good" or "elegant" with "clever". Simple code can also be "good" and "elegant".

    If you have configurable maze levels, then maybe you should just do the pathfinding when you initially configure the mazes. Simplest would be to get the maze designer to do it by hand. I'd only bother automating this if you have a bazillion mazes ... or users can design them.

    (Aside: if the routes are configured by hand, the maze designer could make a level more interesting by using suboptimal routes ... )

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-29 18:06

    Knowing that pacman paths are non-random (ie, each specific level 0-255, inky, blinky, pinky, and clyde will work the exact same path for that level).

    I would take this and then guess there are a few master paths that wraps around the entire maze as a "return path" that an eyeball object takes pending where it is when pac man ate the ghost.

    0 讨论(0)
  • 2021-01-29 18:06

    The ghosts in pacman follow more or less predictable patterns in terms of trying to match on X or Y first until the goal was met. I always assumed that this was exactly the same for eyes finding their way back.

    0 讨论(0)
  • How about each square having a value of distance to the center? This way for each given square you can get values of immediate neighbor squares in all possible directions. You pick the square with the lowest value and move to that square.

    Values would be pre-calculated using any available algorithm.

    0 讨论(0)
提交回复
热议问题