I am creating a pacman game in javascript to learn the language, and most of its elements are beautifully executed, with the exception of ... 4 ghosts of AI. Right now I am using a fairly simple approach (for example, searching for x and y and trying to get closer to pacman if the ghosts hit the wall or another ghost e tries to peel off by moving in a random direction until it hits another wall or ghost). The fact is that this approach is simply not good, in most cases ghosts are stuck between them for some time or go into very unstable directions. I want to ask what approach could be for building this AI, given that this is javascript? I am not asking for the code to be made here, just some ideas to get me to detach from this.
PS: I was thinking about graphs and Disjktra et all, but given that the game is in the matrix, and calculating 4 graphs + the path every 250 ms can be very expensive ....
source share