A sophisticated maze generation and solving game implemented in C with SDL graphics support. This project demonstrates advanced algorithms for maze generation using Randomized Depth-First Search and provides an interactive gaming experience with multiple difficulty levels.
- Features
- Screenshots
- Algorithm Overview
- Prerequisites
- Installation
- Usage
- Project Structure
- Technical Details
- Controls
- Building from Source
- Contributing
- License
- Interactive Graphics: Beautiful SDL-based graphical interface
- Multiple Difficulty Levels: Easy, Medium, and Hard maze configurations
- Real-time Maze Generation: Watch mazes being generated using advanced algorithms
- Intelligent Maze Solving: Automatic pathfinding with visual solution display
- Responsive Controls: Smooth keyboard navigation and menu interaction
- Visual Feedback: Interactive ball movement and trophy collection
- Randomized DFS Algorithm: Advanced maze generation using depth-first search
- Memory Efficient: Optimized data structures and memory management
- Modular Design: Clean separation of concerns with well-organized modules
- Cross-platform Compatible: Runs on Linux, macOS, and Windows
- Professional Documentation: Comprehensive code documentation with Doxygen-style comments
- Initialization: Start with a grid of cells, all walls intact
- Random Selection: Choose a random starting cell and mark it as visited
- Neighbor Analysis: Find all unvisited neighboring cells
- Random Movement: Randomly select an unvisited neighbor
- Wall Removal: Remove the wall between current cell and chosen neighbor
- Stack Management: Push current cell to stack and move to neighbor
- Backtracking: When no unvisited neighbors exist, pop from stack
- Completion: Continue until all cells have been visited
- Path Tracking: Use a stack to maintain the current path
- Direction Selection: Randomly choose valid directions (open passages)
- Dead End Handling: Backtrack when reaching dead ends
- Solution Path: Return the complete path from entry to exit
- Operating System: Linux (Ubuntu/Debian recommended), macOS, or Windows with WSL
- Compiler: GCC with C99 support or later
- Memory: Minimum 64MB RAM
- Display: Support for graphical display (for SDL interface)
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install build-essential libsdl1.2-dev libsdl-image1.2-dev pkg-config
# macOS (with Homebrew)
brew install sdl sdl_image pkg-config
# Fedora/CentOS/RHEL
sudo yum install gcc make SDL-devel SDL_image-devel pkgconfig# Clone the repository
git clone https://github.com/HamzaBenyazid/labyrinth.git
cd labyrinth
# Build the project
make
# Run the game
./bin/labyrinth- Download: Clone or download the project files
- Dependencies: Install SDL development libraries (see Prerequisites)
- Compile: Use the provided Makefile or compile manually
- Execute: Run the generated executable
./bin/labyrinth- Main Menu: Choose to start a new game or view controls
- Difficulty Selection: Select Easy (10x10), Medium (15x15), or Hard (20x20)
- Maze Generation: Watch the maze being generated in real-time
- Navigation: Use arrow keys to move through the maze
- Objective: Reach the trophy (exit point) to complete the level
- Solution: Press 'S' to reveal the solution path
labyrinth/
โโโ ๐ src/ # Source code files
โ โโโ ๐ main.c # Application entry point
โ โโโ ๐ maze_generator.c # Maze generation algorithms
โ โโโ ๐ maze_solver.c # Maze solving algorithms
โ โโโ ๐ stack.c # Stack data structure implementation
โ โโโ ๐ display.c # Console display functions
โ โโโ ๐ sdl_display.c # SDL graphics interface
โโโ ๐ include/ # Header files
โ โโโ ๐ maze_generator.h # Maze generation declarations
โ โโโ ๐ maze_solver.h # Maze solving declarations
โ โโโ ๐ stack.h # Stack data structure declarations
โ โโโ ๐ display.h # Display function declarations
โ โโโ ๐ sdl_display.h # SDL interface declarations
โโโ ๐ images/ # Game assets and graphics
โ โโโ ๐ผ๏ธ background.png # Game background
โ โโโ ๐ผ๏ธ controls.png # Control instructions
โ โโโ ๐ผ๏ธ difficulty icons # Difficulty level icons
โ โโโ ๐ผ๏ธ game sprites # Ball, trophy, and other sprites
โโโ ๐ bin/ # Compiled binaries (generated)
โโโ ๐ Makefile # Build configuration
โโโ ๐ README.md # Project documentation
typedef struct _cell {
int right; // Right wall status (0/1/-1)
int left; // Left wall status
int up; // Top wall status
int down; // Bottom wall status
} cell;typedef struct _stack {
int column; // Column coordinate
int row; // Row coordinate
struct _stack *next; // Next node pointer
} stack;- Time: O(n) where n is the number of cells
- Space: O(n) for the visited array and stack
- Worst Case: O(4^n) for backtracking
- Average Case: O(n) for most mazes
- Space: O(n) for the solution path stack
- Dynamic allocation for maze matrices
- Proper cleanup of stack structures
- SDL surface management for graphics
- No memory leaks in normal operation
- Arrow Keys: Navigate menu options
- Enter/Space: Select menu item
- Escape: Return to previous menu or quit
- โ Arrow: Move up
- โ Arrow: Move down
- โ Arrow: Move left
- โ Arrow: Move right
- S Key: Show/hide solution path
- R Key: Restart current maze
- Escape: Return to main menu
- Easy: 10ร10 maze - Perfect for beginners
- Medium: 15ร15 maze - Moderate challenge
- Hard: 20ร20 maze - For experienced players
# Clean previous builds
make clean
# Build the project
make
# Run with debug information
make debug
# Install system-wide (optional)
make install# Create build directory
mkdir -p bin
# Compile source files
gcc -Wall -Wextra -pedantic -g `pkg-config --cflags sdl` -Iinclude -c src/*.c
# Link the executable
gcc *.o -o bin/labyrinth `pkg-config --libs sdl` `pkg-config --libs SDL_image`
# Clean object files
rm *.o# Build with debug symbols and additional warnings
make DEBUG=1
# Run with memory checking (if valgrind is installed)
valgrind --leak-check=full ./bin/labyrinthWe welcome contributions to improve the Labyrinth project! Here's how you can help:
- ๐ Bug Reports: Report issues or unexpected behavior
- ๐ก Feature Requests: Suggest new features or improvements
- ๐ง Code Contributions: Submit pull requests with enhancements
- ๐ Documentation: Improve or expand documentation
- ๐จ Assets: Contribute graphics, sounds, or visual improvements
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test thoroughly
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style and formatting
- Add appropriate documentation for new functions
- Include unit tests for new functionality
- Ensure memory management is proper
- Test on multiple platforms when possible
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Hamza Ben Yazid and Mohammed Bekraoui
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- SDL Development Team: For the excellent SDL library
- Algorithm Inspiration: Classic maze generation algorithms from computer science literature
- Community: Thanks to all contributors and users who help improve this project
- GitHub Issues: Report bugs or request features
- Email: hamzabyazid@gmail.com
Made with โค๏ธ by @HamzaBenyazid and @meedbek
Happy maze solving! ๐ฎโจ
