I made a Pac-man AI in blocks. You are Blinky, the Red Ghost and have to chase Pac-man. The Pac-man AI is loosely based on the original ghost ai by Dr. Iwatani at Atari, but has three modes. Feed Mode, which is random grazing, Flight mode which is activated if Blinky gets close, and Fight mode after eating a power pellet.
I had a full game version with all the animations from the original sprite sheets, etc., but it MakeCode kept telling me the code was too large to publish… So this is a really stripped down version. You can add the animation for when Blinky turns blue to help you see when it is time to run.
More importantly, you can set debug mode to 1 and let the camera follow Pac-man to see his ai at work.
The AI uses an underlying tile map that also stores the uneaten pellets. The tile map allows Pac-man to check his surroundings to see which maze paths are available at the intersections. The on-game-update loop only allows Pac-man to make one decision each time he enters a tile. In order to make another decision, he has to move to a different tile. This prevents him from doing things like repeatedly reversing himself.
***edit: the link below is to the full version