Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

algorithm for monsters in simple pacman in swing  RSS feed

 
richa redkar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M looking out for simple and best algorithm for pacman in swing.
 
Jason Kingsley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this particularly belongs in the Swing forum, as it's more algorithm based and not particularly Swing orientated other than the assumption that you'll be using Swing.

Anyway, that aside, if you consider that a ghost only ever moves in a straight line, continuing in the direction it was travelling in until it meets a junction, or a wall then at such points the ghost needs to make a decision:

1) which direction leads me to Pacman?

This might involve it backtracking, turning if the junction allows, reversing if the path is a dead end or continuing in the same direction.

It's a relatively trivial task to maintain a direction vector to Pacman.

It is possible to spot a flaw in this algorithm though, in that the ghost is always chasing Pacman - play testing may suggest this is enough but if we move the analogy over to a missile (still an object hunting a target) what they track is an intercept path, ie, to where it thinks the target will be given the targets vector and its own vector.

This though might be too complicated. There must be plenty of resources on the net for doing such - make use of that Internet Oracle - Google.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also in Pacman all four ghosts do not just follow Pacman; if they did you would die very quickly. So there is a different algorithm for each ghost A quick look on some of the emulation boards (the MAME message board at http://www.mame.net/msg) might be useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!