Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

A robust and interactive Sudoku puzzle solver built in C++ featuring object-oriented design, automatic puzzle generation, and comprehensive error handling.

Notifications You must be signed in to change notification settings

zisshh/sudoku-solver-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Sudoku Solver CLI

Sudoku CLI Demo

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.

Features

  • 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 Sudoku class 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.

Requirements

  • C++11-compatible compiler (tested with g++ on macOS)
  • Standard C++ library only; no external dependencies

Getting Started

  1. Clone the repository:
    git clone https://github.com/zisshh/sudoku-solver-CLI.git
    cd sudoku-solver-CLI
  2. Compile the project:
    g++ -std=c++11 -o sudoku main.cpp Sudoku.cpp
  3. Run the executable:
    ./sudoku
  4. Solve or Generate:
    • Choose option 1 to solve a puzzle from a file such as puzzle.txt (9x9 grid, zeros for blanks).
    • Choose option 2 to generate an Easy, Medium, or Hard puzzle on the fly.

Project Structure

├── 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)

Implementation Highlights

  • Const-Correct Interfaces: Read-only helpers are marked const to enforce immutability where possible.
  • Helper Encapsulation: Internal checks like isSafe remain private to the Sudoku class, 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.

Future Enhancements

  • 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.

License

This project is released under the MIT License. See LICENSE for details.

About

A robust and interactive Sudoku puzzle solver built in C++ featuring object-oriented design, automatic puzzle generation, and comprehensive error handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages