A complete Sudoku game with a beautiful PySide6 GUI and built-in solver.
- Three Difficulty Levels: Easy, Medium, and Hard
- Intelligent Puzzle Generation: Creates valid puzzles with unique solutions
- Built-in Solver: Uses backtracking algorithm to solve any valid Sudoku
- Interactive GUI: Clean, modern interface built with PySide6
- Game Features:
- New Game generation
- Hints system
- Solution checker
- Reset to initial puzzle
- Show complete solution
- Visual distinction between initial clues and user entries
- Install the required dependency:
pip install PySide6To launch the interactive game:
python -m sudokuOr explicitly:
python -m sudoku --guifrom sudoku import SudokuBoard, generate_puzzle, solve_sudoku
# Create a new game
board = SudokuBoard('medium')
# Get puzzle and solution
puzzle, solution = generate_puzzle('hard')
# Solve a puzzle
import copy
puzzle_copy = copy.deepcopy(puzzle)
solve_sudoku(puzzle_copy)
print(puzzle_copy)
# Access board properties
value = board.get_cell(0, 0)
board.set_cell(1, 1, 5)
is_initial = board.is_initial_cell(0, 0)
board.get_hint()
board.reset()
board.solve()- Difficulty Dropdown: Select Easy, Medium, or Hard
- New Game: Generate a new puzzle with selected difficulty
- Hint: Reveal one cell from the solution
- Check: Verify if your current solution is correct
- Solve: Show the complete solution
- Reset: Clear all user entries and return to initial puzzle
- Launch the game
- Select your difficulty level
- Click "New Game" to generate a puzzle
- Click on any white cell to enter a number (1-9)
- Initial puzzle numbers (gray cells) cannot be changed
- Use "Hint" if you're stuck
- Use "Check" to verify your progress
- Complete the puzzle so each row, column, and 3x3 box contains digits 1-9
- Generates a complete, valid Sudoku board by:
- Filling diagonal 3x3 boxes with random numbers
- Using backtracking to complete the remaining cells
- Removes cells while ensuring unique solution:
- Easy: 40-45 clues remain
- Medium: 30-35 clues remain
- Hard: 25-30 clues remain
- Validates that each removal maintains exactly one solution
Uses a backtracking algorithm:
- Find next empty cell
- Try digits 1-9
- Check if digit is valid (no conflicts in row, column, or 3x3 box)
- Recursively solve remaining cells
- Backtrack if no valid solution found
sudoku/
├── __init__.py # Package exports
├── __main__.py # Command-line entry point
├── _sudoku.py # Board logic and puzzle generation
├── _solve_engine.py # Solver algorithms
└── _gui.py # PySide6 GUI implementation
- Python 3.7+
- PySide6
See main repository LICENSE file.
Created as a complete Sudoku game implementation with modern GUI and efficient solving algorithms.