Pac-Man AI

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




Looks great!

Could you save the full game as PNG? I would like to take a look.

Also as a workaround, you can remove blocks file and it will probably let you publish.


Here is a .png from the saved from makecode arcade, but I think it is just the image. Im not sure how to delete the blocks portion–can you point me to some instructions for that?

Switch to Javascript, expand explorer on the left and hit the trashcan button next to main.blocks.

After removing blocks it can be published -

The TS code is around 150k, if you remove the white background image it goes down by 40k (there are two background images - one if them a real picture and another just white). The blocks code is around 1000k, half of which is indentation. I guess we would need to look into some better way of storing these…

Did you actually program the whole thing in blocks? This is impressive!

1 Like

Haha–yes I did it all in blocks except for a few of the tabular items. Thanks for uploading for me!

Do you have any way of helping me figure out why the death animation for Pac-man seems to start at a random frame and end at a random frame? It seems like it rarely starts and stops on the right frames, and I have tried everything I could think of to force the right start and stop frames with no success…

1 Like