Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Coding Pacman?

I need a plausible algorithm for the sprites (ghosts) to go through. This algorithm must be able to chase the Pacman. The location is known of the Pacman. I can get these ghosts to follow it, but the problem is when they approach a wall, they keep on trying to go towards the Pacman and get stuck. I later tweaked it so if it cannot move, it goes in a random direction, but this is very inefficient. It could take minutes, hours, even days for it to get the perfect random directions to go into so it can correctly follow it. I have tried searching for a way to follow it with no luck.

Any ideas on a way to do this?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Pathing isn't exactly an easy algorithm to create. However, if I were doing this, I'd make each "walkable square" a logical node. Then, you can calculate the shortest path between two nodes (the ghost node and the player node) using any standard shortest-path algorithm, such as Dijkstra's algorithm.

  • 1 decade ago

    Well, you've got your preferred direction, which is toward the pacman. if your grid is 100x100 and pacman is (for example) at 0, 0 and you are at 50,50, you want to move -1,-1.

    But, 49,49 is a wall. Instead of moving random, have them look try to move *one* of the directions.

    when they can't move in either direction, you can have them try and move toward the actual center of the board until they have a better shot at the pacman.

Still have questions? Get your answers by asking now.