by Sandro Maffiodo


This is not a pizza. Obviously this is a tribute to the famous PAC MAN game.


$(CC) prog.c -lSDL -o prog


cat level-ioccc | ./prog && echo YOU WIN!


cat level-classic | ./prog && echo YOU WIN!

The program return zero if you win, not-zero if you are a loser.


This simple program is a partial implementation of the original PAC MAN . The gameplay is a bit ' different : Ghosts , once eaten , never become two eyes and never return ghosts . This difference made ​​the game easier.

The program does not count the lives or points . Just wait until the player dies or wins ( by collecting all points / coins ) .

The program does not implement a traditional pathfinding algorithm , but use one that I wrote specifically for the event ( see chapter Pathfinding ) .

The description of the level is read from stdin so you can customize what you want . You can add ghosts , walls and dots .

The game sprites are contained in a single bitmap that you can change, if you like.


Each line must be 21 characters long.

These are the supported characters:


Instead of implementing one of the standard pathfinding algorithms i've decided to write a cooperative pathfinding algorithm that use a single weighted map for all ghosts. The code is small and seems to do the job.

The algorithm follow these three rules:

  1. every time the player moves, the global weighted table is computed using this formula:

    cell.weight = manhattan_distance(cell.pos, pacman.pos)

    If the cell is a wall its weight is infinitely great.

  2. each ghost moves to one of its nearest cells (up, down, left, right), choosing the one with the lowest weight

  3. when a ghost leaves a cell, the cell weight is multiplied by two


The program will not terminate until the player win or dies. Press ESCAPE to quit.


This program require SDL1.X to compile.

The build process will generate some warnings (39~ on clang) about: