sudoku is a simple playable Sudoku Game which is built using pygame
in Python. It is a graphical-user interface based project.
Date of creation: 27 June, 2021
This project is a single-player. After choosing a difficulty level, the player can start solving the puzzle on the 9×9 Grid.
The following features are provided in the game:
- Three difficulty levels, i.e., easy, medium, and hard
- A sudoku-generator that generates random sudoku-grids
- A sudoku-solver that solves a sudoku-grid using backtracking
- Visualization of working of the solving-algorithm, with variable speed
- Left-click (on a box/cell): Select the cell
- Arrow Keys: Change the selected cell
- Backspace/Delete: Empty out the selected cell
- Numbers (1-9): Enter the number in the selected cell
- Numbers (1-9) on numeric-keypad: Enter upto 4 guesses in the cell
Note: Enter an already entered number in the selected cell to remove it. Guesses are inserted in a FIFO manner.
The solving-algorithm has been slowed down to visualize the backtracking. To change its speed, go to Line 78 in main.py
and change the value of the variable SOLVING_DELAY
:
- Increase the speed by decreasing the DELAY
- Decrease the speed by increasing the DELAY
For reference, Line 78 is the following variable definition:
SOLVING_DELAY: int = 50
Time complexity of Solver: O(9ᴹ)
, where M
is the number of unfilled cells (Attributing to the fact that there are 9 possibilities for each empty cell).
- Difficulty level corresponds to the number of initially filled cells in the grid. The harder the level, the fewer initial values are given in the grid.
- The number of cells initially given are chosen randomly according to the selected level.
- Some sudoku-grids have multiple solutions.
- Do not close the application while the algorithm is solving the Sudoku as ongoing system processes may cause the app to crash.
To play, clone the repository on your device, navigate to the folder, and execute:
python3 main.py