I am creating a Pacman game in javascript to learn the language, and the most elements of it are done nicely except... the 4 ghosts AI. Right now I am using a pretty basic approach (like searching for x and y and try to get closer to Pacman, if the ghosts hit a wall or other ghost e tries to unstick himself by going into a random direction until it hits another wall or ghost). The thing is, this approach is just not good at all, most of the time ghosts get stuck between them for some time, or go to very erratic directions. What I want to ask is, what could be an approach for constructing this AI considering this in javascript? I am not asking for already done code here, just some ideas to get me unstuck on this.
PS: I've thought of graphs and Disjktra et all, but, considering that the game is in a matrix and calculating 4 graphs + path every 250ms can be a lot costly...