Grid Guru is a feature-complete Sudoku puzzle solver implemented in C with a GTK-based graphical interface. Designed for both enthusiasts and developers, it combines algorithmic problem-solving with intuitive user interaction. This project emphasizes code clarity, efficient backtracking, and robust error handling while demonstrating practical GUI development in C.
- Project Overview
- Key Features
- Installation
- File Structure & Implementation
- Design Choices & Rationale
- Usage Guide
- Screenshots
- Future Improvements
- Acknowledgments
- License
Grid Guru solves Sudoku puzzles using a backtracking algorithm, rendered through a GTK 3 GUI. Users can input puzzles, validate their correctness, solve them, and reset or revert changes. The project serves as a case study in:
- Algorithm Design: Efficient backtracking for constraint satisfaction problems.
- GUI Development: GTK widget management, event handling, and state synchronization.
- Software Engineering: Modular code structure, error handling, and build automation.
- Interactive GTK Interface:
- Input cells with validation (digits 1–9 or empty).
- Visual feedback for invalid configurations.
- Backtracking Solver: Recursive algorithm to find valid solutions.
- State Management:
- Solve: Computes and displays the solution.
- Reset: Clears the grid to zeros.
- Back: Reverts to the user’s original input post-solution.
- Input Sanitization: Rejects non-digit characters and out-of-range values.
- GTK 3: GUI framework.
- GCC: C compiler.
- Make: Build automation.
# Clone
git clone https://github.com/Shoaib-Programmer/GridGuru.git
cd GridGuru
# Debian/Ubuntu
sudo apt install build-essential libgtk-3-dev
# macOS (Homebrew)
brew install gtk+3
# Build and Launch
make # Compile
bin/grid_guru # Run
- Purpose: GTK GUI setup and event handling.
- Key Components:
create_main_window()
: Initializes the 9x9 grid ofGtkEntry
widgets with stylistic subgrid separators.on_solve_button_clicked()
: Validates the puzzle, triggers the solver, and updates the UI.- State Management: Toggles button visibility (Solve/Back) and syncs the grid with
initial_grid
.
- Purpose: Core Sudoku logic.
- Functions:
isValid()
: Checks row, column, and 3x3 subgrid constraints.solveSudoku()
: Recursive backtracking implementation.
- Algorithm: Prioritizes empty cells dynamically (no fixed order) for efficiency.
- Header file declaring function prototypes (
isValid
,solveSudoku
) and constants (SIZE=9
).
- Build Automation: Compiles
main.c
andsudoku.c
intogrid_guru
. - Targets:
all
: Default build.clean
: Remove binaries.run
: Compile and execute.
- Directory for screenshots demonstrating UI states:
initial-state.png
: Default puzzle.solved-state.png
: Post-solution.invalid-state.png
: Error feedback.nosolution-state.png
: No solution exists.
- Why GTK?
- Native Performance: Lightweight compared to Electron or web-based tools.
- C Compatibility: Direct integration without language bindings.
- Tradeoff: Steeper learning curve vs. simplicity of terminal-only solvers.
- Choice: Classic recursive backtracking.
- Rationale:
- Simplicity: Easy to implement and debug for a 9x9 grid.
- Adequate Performance: Solves most puzzles in <1ms.
- Limitation: Not optimized for "hard" Sudokus with sparse initial clues.
initial_grid
Array: Stores the user’s initial input to enable the "Back" functionality.- Why Global State? Simplifies callback handling in GTK without passing structs.
- Sanitization: In
get_grid_from_entries()
, invalid characters are coerced to0
. - Pre-Solve Check:
isValid()
ensures no duplicates before invoking the solver.
- Launch: Run
./grid_guru
to load the default puzzle. - Input: Click cells and type numbers (1–9). Leave empty for unknowns.
- Solve: Click "Solve" to compute the solution (if valid).
- Reset: "Reset" clears all cells.
- Back: After solving, "Back" restores your original input.
Initial Puzzle | Solved State | Invalid Input | No Solution |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
- GTK Team: For maintaining the GUI framework.
- Classic Sudoku Literature: Inspired the backtracking approach.
MIT License. See LICENSE for details.