I would share the code but it is in gdevelop4 and I don’t think you should start with that…
However, the whole game came to be after I had a conversation here with a guy who was trying to get the AI pacman to work and I was trying to help… Check this post where I have a link to a working prototype. You should be able to figure it out…