# Pac-Man AI

**URL:** <https://forum.makecode.com/t/pac-man-ai/550>\
**Category:** Arcade\
**Tags:** game\
**Created:** [September 19, 2019, 1:32am UTC](https://forum.makecode.com/t/pac-man-ai/550 "2019-09-19T01:32:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlj1978](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jlj1978](https://forum.makecode.com/u/jlj1978)\
**Post date:** [September 19, 2019, 1:32am UTC](https://forum.makecode.com/t/pac-man-ai/550/1 "2019-09-19T01:32:24Z")

</div>

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

Enjoy!

> **[Chase Pac-man](https://arcade.makecode.com/87814-14264-07477-09638)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
 ![arcade-Chase-Pac-man](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/8c498b23f471e5b80e98d8923f5edf05cbe37113.png)

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [September 19, 2019, 9:53am UTC](https://forum.makecode.com/t/pac-man-ai/550/2 "2019-09-19T09:53:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jlj1978](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jlj1978](https://forum.makecode.com/u/jlj1978)\
**Post date:** [September 19, 2019, 10:29am UTC](https://forum.makecode.com/t/pac-man-ai/550/3 "2019-09-19T10:29:19Z")

</div>

![arcade-Chase-Pac-man%20(2)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/8409caaed1c8592a8484d73b7b29a66d33aab83f.png)

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?

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [September 19, 2019, 1:47pm UTC](https://forum.makecode.com/t/pac-man-ai/550/4 "2019-09-19T13:47:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [September 19, 2019, 5:45pm UTC](https://forum.makecode.com/t/pac-man-ai/550/5 "2019-09-19T17:45:03Z")

</div>

After removing blocks it can be published - [https://makecode.com/\_eVk5FJ2mp3bL](https://makecode.com/_eVk5FJ2mp3bL)

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!

---

<div class="post-metadata">

**Author:** ![jlj1978](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jlj1978](https://forum.makecode.com/u/jlj1978)\
**Post date:** [September 19, 2019, 6:44pm UTC](https://forum.makecode.com/t/pac-man-ai/550/6 "2019-09-19T18:44:47Z")

</div>

> [@mmoskal](#):
>
> [https://makecode.com/\_eVk5FJ2mp3bL](https://makecode.com/_eVk5FJ2mp3bL)

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…
