### GRASP CODING

PYTHON CODE | AI CODE | UI/UX CODE

AI Free Code

# Sudoku Solver with steps – AI Game

Sudoku, a puzzle in which players insert the numbers one to nine into a grid consisting of nine squares subdivided into a further nine smaller squares in such a way that every number appears once in each horizontal line, vertical line, and square. Today we are going to build a model for the Sudoku Solver program using OpenCV, Deep Learning, and Backtracking Algorithm are used to solve the puzzle. First, build the Character Recognition model that can extract digits from a Sudoku grid image and then work on a backtracking approach to solve it.

#### APPROACH:

Here, we can divide the process into 3 Parts:

• 1. Looking for a sudoku puzzle in the image.
• 2. Extracting numbers from sudoku.
• 3. Solving the Sudoku using backtracking.

#### DEPENDENCIES

Deep Learning based AI_Sudoku_Solver architecture uses OpenCV (opencv==4.2.0) and Python (python==3.7). The model Convolution Neural Network(CNN) uses Keras (keras==2.3.1) on Tensorflow for Digit Recognition.

#### Following are the technologies used for the sudoku solver game:

• 1. Image Recognition: CNN trained using Keras

• 2. Image Processing: OpenCV

• 3. The algorithm used to solve sudoku: Peter Novig’s optimized version of backtracking

#### HOW TO EXECUTE CODE:

• 1. You will first have to download the repository and then extract the contents into a folder.
• 2. DMake sure you have the correct version of Python installed on your machine. This code runs on Python 3.6 above.
• 3. Now, install the required libraries.
• 4. Now, you can use pretrained digit recognition model, it’s inside Resources Folder. The MNIST is used for digit recognition using Deep Learning CNN model.
• 5. Now, Open terminal and type the following command:
• ` python Main.py -i "path to sudoku image" `

The above command is used for solving sudoku in images, and for real-time sudoku solver, use webcam (Opencv for capturing Video).

Note: Apart from the auto solve of the Sudoku Game, the game can also be played by User.

#### REFERENCES:

• 1. Sudoku Solver
• 2. Digit Recognition
• 3. Backtracking Algorithm