A comprehensive C-based Sudoku application with a graphical user interface featuring both a powerful puzzle solver and an interactive game mode. This dual-function application allows users to solve existing puzzles or play new randomly generated ones with hints and solution checking.
- Interactive GUI: Easy-to-use 9x9 grid for inputting puzzles
- Fast Solving: Uses backtracking algorithm for quick solutions
- Input Validation: Only accepts valid numbers (1-9) and checks for duplicates
- Visual Feedback: Clear separation of 3x3 blocks
- Example Puzzles: Load sample puzzles to test the solver
- Puzzle Generation: Create random, solvable Sudoku puzzles
- Solution Checking: Verify if your completed puzzle is correct
- Hint System: Get up to 3 hints per puzzle to help you solve
- Difficulty Levels: Medium difficulty puzzles with proper number of clues
The Game tab provides an interactive Sudoku experience:
- Automatic generation of valid Sudoku puzzles with unique solutions
- Each puzzle is guaranteed to be solvable using logic (no guessing required)
- Three difficulty levels (easy, medium, hard) with different numbers of clues
- Real-time input validation prevents obvious mistakes
- Built-in hint system (limited to 3 hints per puzzle)
- Solution checking compares your answer with the known solution
- Clear visual feedback on correct/incorrect solutions
- Puzzle generation uses a diagonal-first approach for efficiency
- Difficulty is controlled by the number of clues removed
- The hint system strategically reveals cells to guide players
- All puzzles have exactly one solution to ensure fairness
- GCC compiler (MinGW recommended for Windows)
- Windows operating system
If you are on Windows and do not have make installed:
- You can use the provided PowerShell script:
.\build.ps1
- Or, compile directly with GCC:
gcc -Wall -Wextra -std=c99 -O2 -o sudoku_solver.exe src/main.c src/sudoku.c src/gui.c -lgdi32 -luser32 -lkernel32 -lcomctl32
If you have make installed (Linux/macOS or Windows with MinGW/MSYS2):
- Compile the project:
make
- Or for quick build:
make quick
- Run the program: Double-click
sudoku_solver.exeor runmake run - Enter puzzle: Click on cells and enter numbers 1-9 in the Solver tab
- Solve: Click "Solve Puzzle" button to find the solution
- Clear: Use "Clear Grid" to start over
- Load Example: Click "Load Example" to try a sample puzzle
- Generate Puzzle: Click "Generate Puzzle" to create a new random puzzle
- Play: Fill in the empty cells with numbers 1-9
- Check Solution: Click "Check Solution" when you think you've solved it
- Get Hints: Use "Get Hint" button (3 hints available per puzzle)
- Switch Tabs: Click between "Solver" and "Game" tabs at the top
Try entering this puzzle:
5 3 _ | _ 7 _ | _ _ _
6 _ _ | 1 9 5 | _ _ _
_ 9 8 | _ _ _ | _ 6 _
------+-------+------
8 _ _ | _ 6 _ | _ _ 3
4 _ _ | 8 _ 3 | _ _ 1
7 _ _ | _ 2 _ | _ _ 6
------+-------+------
_ 6 _ | _ _ _ | 2 8 _
_ _ _ | 4 1 9 | _ _ 5
_ _ _ | _ 8 _ | _ 7 9
Uses backtracking algorithm:
- Find empty cell
- Try numbers 1-9
- Check if placement is valid (row, column, 3x3 box)
- If valid, recursively solve rest
- If no solution, backtrack and try next number
The Game tab uses an advanced puzzle generation approach:
- Fill diagonal 3x3 boxes first (these don't affect each other)
- Solve the rest of the grid using the solver algorithm
- Remove numbers strategically to create a puzzle with a unique solution
- Different difficulty levels remove different numbers of clues
sudoku_solver/
├── src/
│ ├── main.c # Entry point and window creation
│ ├── sudoku.c # Solving and puzzle generation algorithms
│ ├── sudoku.h # Sudoku function declarations
│ ├── gui.c # GUI implementation (solver & game tabs)
│ └── gui.h # GUI function declarations & constants
├── Makefile # Build configuration
├── build.ps1 # PowerShell build script for Windows
└── README.md # This file
- Language: C (C99 standard)
- GUI: Windows API (native) with Common Controls
- Solver Algorithm: Backtracking with constraint checking
- Generation Algorithm: Diagonal-first with unique solution guarantee
- Tab Interface: Windows Common Controls Tab Control
- Time Complexity: O(9^n) worst case, typically much faster
- Space Complexity: O(1) excluding recursion stack
- Hint System: Limited hints (3 per puzzle) based on known solution
The Solver tab allows you to input and solve any valid Sudoku puzzle:

The Game tab lets you play randomly generated puzzles:

Feel free to submit issues and enhancement requests! Some ideas for future improvements:
- Additional difficulty levels in Game mode
- Puzzle saving/loading functionality
- Timer for gameplay
- Score tracking and statistics
- Support for additional operating systems
This project is open source. Feel free to use and modify as needed.