This project presents an interactive solution to the classic Tower of Hanoi problem, implemented in C. It includes:
- Recursive and iterative algorithms to solve the problem.
- Graphical visualization of the solution process using the Raylib library.
- Performance metrics, such as time complexity and move count, displayed during execution.
- Interactive Simulation: Select the number of disks and the algorithm (recursive or iterative) to observe the solution dynamically.
- Graphical Visualization: Disks and towers are visualized interactively, showing the movement of disks step-by-step.
- Performance Analysis:
- Execution time displayed in milliseconds.
- Total number of moves calculated and displayed.
- Verification Algorithm: Ensures the solution follows the rules of the Tower of Hanoi.
To compile and run the project, you will need:
- A C compiler (e.g., GCC).
- The Raylib library for graphical rendering.
- Audio support for sound effects (optional but recommended).
-
Clone this repository:
git clone https://github.com/yourusername/tower-of-hanoi-visualization.git cd tower-of-hanoi-visualization
-
Install Raylib:
- For Linux:
sudo apt install libraylib-dev
- For Windows: Follow the instructions at Raylib Setup.
- For Linux:
-
Compile the code:
gcc -o hanoi main.c -lraylib -lm -ldl -lpthread
-
Run the executable:
./hanoi
- Launch the application.
- Enter the number of disks (1–15) to simulate.
- Choose the algorithm:
- Iterative: Iteratively solve the Tower of Hanoi.
- Recursive: Solve the problem recursively.
- Watch the visualization as the disks move between towers.
- View performance metrics at the bottom of the screen.
- After completion, the verification process ensures correctness.
main.c
: Entry point of the program. Handles user input, visualization, and algorithm selection.recursive.c
: Recursive Tower of Hanoi solver.iterative.c
: Iterative Tower of Hanoi solver.Include/
: Contains utility headers for visualization and algorithms.
- Uses Raylib for smooth and interactive graphics.
- Dynamic disk movements with audio effects.
- Displays execution time, move count, and disk count during the process.
- Add a graphical UI for algorithm selection and parameter input.
- Support for larger numbers of disks with optimized memory usage.
- Comparative analysis graphs for iterative vs. recursive solutions.
This project was deriged by me CHEMLI Ayoub. Special thanks to the Raylib community for providing an excellent library for graphics.
This project is licensed under the MIT License. See the LICENSE file for details.