This project aims to solve any sudoku of N dimension, where N is a non-prime. The project uses pygame for creating the Graphical User Interface. The project is implemented in two forms -
- An option to load an image saved on the system or use the webcam to feed image to the program and then play the game on the system.
- An option to use Augmented Reality and solve the sudoku by showing the puzzle to the webcam.
The project uses Dancing Links in the form of Algorithm X to find the solution of the Sudoku puzzle. Sudoku is a well known NP-Complete problem and Algorithm X is a means of implementing a form of greedy depth first search to find the appropriate solution. For more understanding on the Sudoku Algorithm, read here. For understanding the Image Processing approach, read here.
You can find the complete concept and implementations explained in detail at the following blog posts -
- Augmented Reality Sudoku Solver — Part I
- Augmented Reality Sudoku Solver — Part II
- Augmented Reality Sudoku Solver — Part III
- Augmented Reality Sudoku Solver — Part IV
Find the suitable pytorch release for your system here.
In my case, this command was used -
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
pip3 install -r requirements.txt
or
pip install -r requirements.txt
To play the game using GUI -
python3 main.py
To use the sudoku solver in CLI, edit the file according to the problem and run -
python3 cli_main.py
Opening Screen
Play Game
Sample Game Loaded
Load from file
Select File
Succesfully Loaded
Load from Camera: 9 X 9
Succesfully Loaded
Load from Camera: 8 X 8
Succesfully Loaded
Load from Camera: 6 X 6
Succesfully Loaded
Load from Camera: 4 X 4
Succesfully Loaded
When an invalid image is clicked
Start Playng the Game
Solving using the Solve Button
Game Won
Augmented Reality Option
Augmented Reality Test: 4 X 4
Augmented Reality Test: 6 X 6
Augmented Reality Test: 8 X 8
Augmented Reality Test: 9 X 9
Augmented Reality Test: 4 X 4
Augmented Reality Test: 6 X 6
Augmented Reality Test: 8 X 8
Augmented Reality Test: 9 X 9
The files in the repository are :
-
The __init__.py file is to make Python treat directories containing the file as packages.
-
This file contains the class for implementing a pygame button.
-
This file contains the class for implementing a camera screen in pygame.
-
This directory contains the images of digits used as the training dataset for the image classifier. It contains images pertaining to digits of the char74k dataset.
-
It is the file containing the weights of the trained model on the
data
directory. -
This zip file contains the complete char74k dataset.
-
This file contains the CNN Classifier for digit recognition.
-
The __init__.py file is to make Python treat directories containing the file as packages.
-
This file contains the class for recognition of the sudoku from image.
-
This file contains helper functions to implement training on GPUs.
-
This file contains details about the algorithm and its implementation.
This directory contains sample images of sudoku puzzles that can be used as test cases for loading the image from file option in the program.
-
This is a copy of the original paper written by
Donald Knuth
on the concept of Dancing Links. -
The __init__.py file is to make Python treat directories containing the file as packages.
-
This file contains details about the algorithm and its implementation.
-
This file contains class to solve Sudoku puzzle.
This directory contains the images for the icons and other media for the README File.
This file can be used to solve sudoku of any dimension using CLI.
This file contains the class for implementing the GUI for the program.
The __init__.py file is to make Python treat directories containing the file as packages.
This file is used as the driver code to start the program.
The Description file containing details about the repository. The file that you looking at right now.
This file contains the respective packages needed to be installed. To install the respective packages, use -
This file contains the default sudoku puzzle which will get loaded incase not last loaded file is found.
Fun Fact: This specific puzzle is designed to work against backtracking as a solution for sudoku and will take almost forever to solve it using backtracking.
- Game Icon: Icon made by Freepik from flaticons.com.
- Camera Icon: Icon made by Freepik from flaticons.com.
- Home Icon: Icon made by Freepik from flaticons.com.
- Rounded Rectangle for Buttons: The code for making rounded rectangle surface in pygame is adapted from here.
- Char74k Dataset: The dataset used for training the CNN to recognize the digits can be found here.
- CNN Model: The Model Architecture is adapted from here.
- Sudoku Solver: The code for implementing Sudoku as an exact cover problem is adapted from here.