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.
- 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
- Console Application: Text-based interface for quick puzzle generation
- Windows Forms GUI: Interactive graphical interface with visual grid separators
- 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
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
- .NET 9.0 SDK or later
- Visual Studio 2022 (recommended) or VS Code
- Windows OS (for GUI application)
-
Clone the repository
git clone https://github.com/SiD-array/sudoku-puzzle.git cd sudoku-puzzle -
Build the console application
cd Suduko dotnet build -
Build the GUI application
cd SudokuGUI dotnet build
cd Suduko
dotnet run <size> <difficulty>Examples:
dotnet run 9 hard # Generate 9x9 hard difficulty puzzle
dotnet run 4 medium # Generate 4x4 medium difficulty puzzlecd SudokuGUI
dotnet runGUI Features:
- Select puzzle size (4x4 or 9x9)
- Choose difficulty level (Easy, Medium, Hard)
- Click "Generate Puzzle" to create a new puzzle
- Fill in the empty cells with numbers
- Click "Validate" to check your solution
- Click "Show Solution" to see the complete answer
- Solved Board Creation: Uses backtracking algorithm to generate a complete, valid Sudoku solution
- Puzzle Creation: Randomly removes cells based on difficulty level:
- Easy: 40% of cells removed
- Medium: 55% of cells removed
- Hard: 75% of cells removed
The validation process checks three Sudoku rules:
- Row Rule: Each row contains numbers 1-9 (or 1-4) without repetition
- Column Rule: Each column contains numbers 1-9 (or 1-4) without repetition
- Box Rule: Each 3x3 (or 2x2) sub-box contains numbers 1-9 (or 1-4) without repetition
- 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
- 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
- Model Layer:
SudokuBoard,SudokuGenerator,Difficultyclasses - ViewModel Layer:
SudokuViewModelfor business logic coordination - View Layer:
ConsoleViewandSudokuFormfor user interfaces
SudokuBoard: Represents the Sudoku grid with methods for manipulation and displaySudokuGenerator: Handles puzzle generation using backtracking algorithmSudokuViewModel: Coordinates between View and Model layersSudokuForm: Main GUI form with interactive controls
- 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
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
- 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
- Generate puzzles and verify they produce valid boards
- Test validation algorithm with correct and incorrect solutions
- Verify input filtering works for both puzzle sizes
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is available for educational purposes.
Siddharth Bhople
- GitHub: @SiD-array
- Date: 18 Oct 2025
- Sudoku puzzle rules and algorithms
- .NET documentation and community
- Visual Studio and development tools
- C# programming best practices
If you encounter any issues or have questions:
- Check the existing issues in the repository
- Create a new issue with detailed description
- Include steps to reproduce any bugs
- Provide system information (OS, .NET version, etc.)
Happy Sudoku Solving! 🧩