A robust terminal-based Sudoku application built with modern C++ that can both solve existing puzzles and generate fresh challenges. The project showcases clean object-oriented design, defensive error handling, and flexible algorithms suitable for extension.
- Two Play Modes: Load puzzles from text files or generate new boards with selectable difficulty.
- Recursive Backtracking Solver: Efficiently fills the grid while respecting row, column, and sub-grid constraints.
- Puzzle Generation: Creates randomized puzzles by removing cells from a solved board using a Mersenne Twister RNG.
- Encapsulated OOP Design: The
Sudokuclass owns the grid, solver, validation, and generator logic to keep the interface tidy. - Robust Error Handling: Graceful messaging for invalid files or unexpected input, preventing undefined states.
- Interactive CLI Menu: Simple navigation loop with input validation and cross-platform screen clearing.
- C++11-compatible compiler (tested with
g++on macOS) - Standard C++ library only; no external dependencies
- Clone the repository:
git clone https://github.com/zisshh/sudoku-solver-CLI.git cd sudoku-solver-CLI - Compile the project:
g++ -std=c++11 -o sudoku main.cpp Sudoku.cpp
- Run the executable:
./sudoku
- Solve or Generate:
- Choose option
1to solve a puzzle from a file such aspuzzle.txt(9x9 grid, zeros for blanks). - Choose option
2to generate an Easy, Medium, or Hard puzzle on the fly.
- Choose option
├── main.cpp # Menu-driven CLI entry point
├── Sudoku.h # Sudoku class interface and Grid type alias
├── Sudoku.cpp # Solver, validation, and puzzle generation implementation
├── puzzle.txt # Sample puzzle input (zeros are empty cells)
└── log.txt # Optional log/output file (if used during development)
- Const-Correct Interfaces: Read-only helpers are marked
constto enforce immutability where possible. - Helper Encapsulation: Internal checks like
isSaferemain private to theSudokuclass, keeping the API lean. - RAII-Friendly Constructors: Objects initialize their board state on construction, preventing partially built puzzles.
- Standard Library First: Uses
std::vector,<random>, and<limits>for portable, dependable behavior.
- Difficulty calibration via advanced heuristics or constraint propagation.
- Exporting generated puzzles to files for later replay.
- Optional GUI front end or web assembly port for broader reach.
This project is released under the MIT License. See LICENSE for details.