A terminal-based program that simulates a robot automatically finding its path through a 10x10 maze using BFS (Breadth-First Search), with a step-by-step animation. Built in C as part of Hack Club Stardance.
The program places a robot (x) at position (0,0) and finds the shortest path to the destination (D) at (9,9) through a maze of obstacles (#). The path is then animated tile by tile in the terminal, and replayed at a faster speed once the robot arrives.
The pathfinding uses BFS (Breadth-First Search):
- Starting at
(0,0), the algorithm explores all reachable cells layer by layer - Each visited cell records its parent — where it came from
- Once
(9,9)is reached, the path is reconstructed backwards through the parent matrix - The path is reversed, then animated step by step using
clear()andusleep()
The maze layout lives in eh_obstaculo(), completely separate from the pathfinding logic. Changing the maze only requires editing that one function.
Linux:
gcc navegacaoauto.c -o robot-maze
./robot-mazeWindows:
gcc navegacaoauto.c -o robot-maze.exe
robot-maze.exePre-built binaries available in Releases.
- How BFS works and why it guarantees the shortest path
- How to implement a queue manually in C using arrays
- How to use a parent matrix to reconstruct a path after traversal
- Why BFS gives you the path backwards and how to reverse it
- How
usleep()and terminal clearing create smooth terminal animations
The biggest challenge was understanding BFS before writing a single line of code. I spent most of the time drawing it on paper, watching explanations, and trying to wrap my head around how the parent matrix actually works. The moment it clicked was thinking of it as water spreading through a maze — it fills every reachable cell layer by layer until it hits the destination.
The second challenge was path reconstruction. BFS naturally gives you the path backwards from destination to start, so reversing it correctly before animating took a few tries to get right.
- C (C99)
- Standard library only:
stdio.h,stdlib.h,string.h,unistd.h - Compiled with GCC