Skip to content

Sudoku puzzle solver implemented in C#, demonstrating algorithmic problem-solving and clean object-oriented design.

Notifications You must be signed in to change notification settings

SiD-array/sudoku-puzzle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Puzzle Generator and Solver

A comprehensive Sudoku application built in C# that generates and solves Sudoku puzzles of different sizes and difficulties. The project includes both a console application and a Windows Forms GUI.

🎯 Features

Core Functionality

  • Multiple Grid Sizes: Support for 4x4 and 9x9 Sudoku puzzles
  • Difficulty Levels: Easy, Medium, and Hard difficulty settings
  • Puzzle Generation: Uses backtracking algorithm to generate valid Sudoku solutions
  • Puzzle Creation: Creates puzzles by removing cells based on difficulty level
  • Solution Validation: Validates user solutions by checking rows, columns, and sub-boxes

User Interfaces

  • Console Application: Text-based interface for quick puzzle generation
  • Windows Forms GUI: Interactive graphical interface with visual grid separators

Technical Features

  • MVVM Architecture: Clean separation of concerns with Model-View-ViewModel pattern
  • Visual Grid Separators: Black lines to clearly delineate 2x2 and 3x3 sub-boxes
  • Input Validation: Real-time input filtering and validation
  • Professional Documentation: Comprehensive XML documentation throughout the codebase

🏗️ Project Structure

sudoku-puzzle/
├── Suduko/                    # Console Application
│   ├── Model/                 # Data models and business logic
│   │   ├── SudokuBoard.cs     # Sudoku grid representation
│   │   ├── SudokuGenerator.cs # Puzzle generation algorithms
│   │   └── Difficulty.cs      # Difficulty level definitions
│   ├── View/                  # User interface layer
│   │   └── ConsoleView.cs     # Console-based UI
│   ├── ViewModel/             # Business logic coordination
│   │   └── SudokuViewModel.cs # ViewModel for console app
│   ├── Program.cs             # Application entry point
│   └── Suduko.csproj          # Console app project file
├── SudokuGUI/                 # Windows Forms Application
│   ├── Form1.cs               # Main GUI form
│   ├── Form1.Designer.cs      # Form designer file
│   ├── Program.cs             # GUI application entry point
│   └── SudokuGUI.csproj       # GUI project file
├── Suduko.sln                 # Visual Studio solution file
└── README.md                  # Project documentation

🚀 Getting Started

Prerequisites

  • .NET 9.0 SDK or later
  • Visual Studio 2022 (recommended) or VS Code
  • Windows OS (for GUI application)

Installation

  1. Clone the repository

    git clone https://github.com/SiD-array/sudoku-puzzle.git
    cd sudoku-puzzle
  2. Build the console application

    cd Suduko
    dotnet build
  3. Build the GUI application

    cd SudokuGUI
    dotnet build

Usage

Console Application

cd Suduko
dotnet run <size> <difficulty>

Examples:

dotnet run 9 hard      # Generate 9x9 hard difficulty puzzle
dotnet run 4 medium    # Generate 4x4 medium difficulty puzzle

GUI Application

cd SudokuGUI
dotnet run

GUI Features:

  1. Select puzzle size (4x4 or 9x9)
  2. Choose difficulty level (Easy, Medium, Hard)
  3. Click "Generate Puzzle" to create a new puzzle
  4. Fill in the empty cells with numbers
  5. Click "Validate" to check your solution
  6. Click "Show Solution" to see the complete answer

🧩 How It Works

Puzzle Generation Algorithm

  1. Solved Board Creation: Uses backtracking algorithm to generate a complete, valid Sudoku solution
  2. Puzzle Creation: Randomly removes cells based on difficulty level:
    • Easy: 40% of cells removed
    • Medium: 55% of cells removed
    • Hard: 75% of cells removed

Validation Algorithm

The validation process checks three Sudoku rules:

  1. Row Rule: Each row contains numbers 1-9 (or 1-4) without repetition
  2. Column Rule: Each column contains numbers 1-9 (or 1-4) without repetition
  3. Box Rule: Each 3x3 (or 2x2) sub-box contains numbers 1-9 (or 1-4) without repetition

🎨 GUI Features

Visual Design

  • Grid Separators: Black lines clearly separate 2x2 and 3x3 sub-boxes
  • Color Coding:
    • Light Gray: Pre-filled cells (read-only)
    • White: Empty cells (editable)
    • Light Yellow: Solution display
  • Professional Layout: Clean, spacious design with proper control positioning

User Experience

  • Real-time Input Validation: Only allows valid numbers (1-9 for 9x9, 1-4 for 4x4)
  • Status Messages: Clear feedback for all user actions
  • Responsive Design: Adapts to different puzzle sizes
  • Error Handling: Comprehensive error handling with user-friendly messages

🔧 Technical Details

Architecture

  • Model Layer: SudokuBoard, SudokuGenerator, Difficulty classes
  • ViewModel Layer: SudokuViewModel for business logic coordination
  • View Layer: ConsoleView and SudokuForm for user interfaces

Key Classes

  • SudokuBoard: Represents the Sudoku grid with methods for manipulation and display
  • SudokuGenerator: Handles puzzle generation using backtracking algorithm
  • SudokuViewModel: Coordinates between View and Model layers
  • SudokuForm: Main GUI form with interactive controls

Data Structures

  • Grid Storage: 2D integer array where 0 represents empty cells
  • Validation: Uses List<int> for duplicate checking
  • Random Generation: Fisher-Yates shuffle algorithm for number randomization

📝 Documentation

The codebase includes comprehensive documentation:

  • File Headers: Each file contains author information and description
  • XML Documentation: All public methods and properties are documented
  • Inline Comments: Complex algorithms and logic are explained
  • Code Style: Follows C# coding standards and best practices

🧪 Testing

Manual Testing

  • Test both 4x4 and 9x9 puzzle generation
  • Verify all difficulty levels work correctly
  • Test GUI validation with complete and incomplete puzzles
  • Verify visual separators display correctly

Validation Testing

  • Generate puzzles and verify they produce valid boards
  • Test validation algorithm with correct and incorrect solutions
  • Verify input filtering works for both puzzle sizes

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is available for educational purposes.

👨‍💻 Author

Siddharth Bhople

🙏 Acknowledgments

  • Sudoku puzzle rules and algorithms
  • .NET documentation and community
  • Visual Studio and development tools
  • C# programming best practices

📞 Support

If you encounter any issues or have questions:

  1. Check the existing issues in the repository
  2. Create a new issue with detailed description
  3. Include steps to reproduce any bugs
  4. Provide system information (OS, .NET version, etc.)

Happy Sudoku Solving! 🧩

About

Sudoku puzzle solver implemented in C#, demonstrating algorithmic problem-solving and clean object-oriented design.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages