1

Im a high school student who is making a Pacman style gridworld game. As you know pacman has ghosts which follow pacman and try and get him. However I am having trouble creating an algortihm that searches for the quickest route to the Pacman object and then takes that route. I have read some blogs online but I havent found anything very helpful. Do you guys have any ideas on going about having the ghost track the packman?

4 Answers4

1

You can try the A* algorithm, as described here.

Eventually you'll notice that the ghosts will adopt mostly the same routes. Check the AI Game Programming Wisdom book series for lots of useful information.

dan
  • 982
  • 8
  • 24
0

Ahh.... Gridworld, I remember that like it was yesterday. Come to think of it, it was... :|

Anyway, the only thing I can think of would be create an ArrayList of all the moves that Pacman makes, pass it along to the ghosts, calculate the quickest path to get to one of the spaces in the list, and then just follow Pacman along.

Wish I could help more, but that's all I can think of right now.

Mr. Mittens
  • 69
  • 4
  • 14
0

It's a bit complicated to provide a full answer here... but look into 'Anti-objects'. There's a paper by Alexander Repenning (University of Colorado). This non-OOP modeling treats the pac-man location in something that's usually described as analogous to a scent.

kineticfocus
  • 492
  • 4
  • 16
0

To find the shortest cost path I would recommend implementing something like Dijkstra's algorithms or Floyd's algorithm (it's benefits would be positive cost edges!)

http://en.wikipedia.org/wiki/Dijkstra's_algorithm http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm

ljlozano
  • 181
  • 10