Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I'm currently making a Pacman game in java. I have a question about the ghosts though.

I understand that the ghosts do not all have the same style of attack. I first want to work on the basics of getting the ghost to go after the Pacman and not worry about there differences yet.

My question to you smart people out there is what would be the best way to make the ghosts chase the Pacman but sometimes randomly divert paths. I'm currently using a 21 by 21 2D array for telling where walls are and such so I was thinking to make it more try and head for the current grid location of Pacman. (for example, go to 10,14) Of course while avoiding going through walls like Pacman. I'm wondering how I could make it do this and also have the ghosts sometimes stop and go another direction or something so that it's not always a constant chase and Pacman has a chance to get away. Maybe some of you have programmed a Pacman game or just know a good way for this. Any help would be greatly appreciated.

(Please note I'm currently in a Grade 11 Computer Science course and halfway through the first semester ever of learned java).

1 Answer

0 votes
by (108k points)

If you just want the ghosts not all to behave the same, each time they encounter an intersection, make their decision a random mix of some reasonable chasing default (such as continuing the way with the shortest distance to Pacman. For the code you can refer the following code:

https://sites.google.com/site/microbytepro/projects/pacman/ai-for-ghosts

And for the encounter between Pacman and the ghosts, you can refer the following link:

https://course.ccs.neu.edu/cs5150f14/assignments/assn1-pacman.pdf

If you wish to know more about Artificial Intelligence then visit this Artificial Intelligence Course.

Browse Categories

...