Objektově orientovaná hra Sudoku vytvořená v Pythonu a knihovně Pygame. Projekt disponuje integrovaným algoritmickým řešitelem (backtracking), moderním uživatelským rozhraním, serializací stavu hry a na událostech založeným přehrávačem hudby na pozadí. Object-oriented Sudoku game built with Python and Pygame. This project features a built-in algorithmic solver (backtracking), a modern UI, game state serialization, and an event-driven background music player.
Ukázka herní plochy a uživatelského rozhraní Game board and user interface showcase
save.json při zavření aplikace pro bezproblémové navázání na hru.
The game automatically saves your progress (including notes, board state, and exact music playback position) to a save.json file when closed, allowing you to resume seamlessly.
.mp3 souborů a využívá Pygame události pro plynulé přechody mezi skladbami.
A built-in music player that reads a playlist of .mp3 files and uses Pygame events to transition smoothly between tracks.
src/ rozložení.
Codebase is fully type-hinted (Python 3.12) and organized using the standard Python src/ layout.
sudoku/
├── assets/ # Icons and music files
│ ├── icon.png # Application window/taskbar icon
│ └── music/ # Directory for background music (.mp3)
├── src/
│ ├── __init__.py
│ ├── config.py # Constants, colors, and dimensions
│ ├── cube.py # Single grid cell logic and rendering
│ ├── grid.py # Main board logic and state management
│ ├── game.py # Game loop, UI, and state machine
│ ├── solver.py # Backtracking algorithm and validation
│ └── ui.py # Interactive button components
├── main.py # Application entry point
├── save.json # Auto-generated save state
└── README.md
Doporučuje se použít virtuální prostředí (venv/conda). It is highly recommended to use a virtual environment (venv/conda).
1. Klonování repozitáře1. Clone the repository
git clone https://github.com/PinkiMan/Sudoku.git
cd Sudoku
2. Instalace závislostí2. Install Dependencies
pip install pygame>=2.5.0
3. Spuštění hry3. Run the game
python main.py
Jádrem auto-solveru je algoritmus s návratem (backtracking), který rekurzivně zkouší možná čísla a vrací se zpět, jakmile narazí na slepou uličku. Tento proces je vizualizován přímo v Pygame okně. The core of the auto-solver is a backtracking algorithm that recursively attempts possible valid numbers, reverting changes when it hits a dead end. This process is visualized directly within the Pygame window.
def solve(grid):
"""
Backtracking algorithm to solve the Sudoku board.
Returns True if solved, False if unsolvable.
"""
empty_cell = find_empty(grid)
if not empty_cell:
return True # Puzzle completely solved
row, col = empty_cell
for num in range(1, 10):
# Check if the number is valid in the current row, column and 3x3 box
if is_valid(grid, num, (row, col)):
grid[row][col] = num
# Recursively try to solve the rest of the board
if solve(grid):
return True
# Dead end reached, backtrack (reset the cell and try next number)
grid[row][col] = 0
return False