Sudoku Game

Sahilbhatiya
2 min readMay 10, 2020

Hello everyone, Today is a great day and i want to show you how i created a sudoku game.

Menu
Game

So this a Game where You can choose levels of your game.

That is easy, medium and hard.

Within few days this will get ready to play.

How to make this:

Following are the rules of Suduku for a player.

  1. In all 9 sub matrices 3×3 the elements should be 1–9, without repetition.
  2. In all rows there should be elements between 1–9 , without repetition.
  3. In all columns there should be elements between 1–9 , without repetition.

The task is to generate a 9 x 9 Suduku grid that is valid, i.e., a player can fill the grid following above set of rules.

A simple naive solution can be.

  1. Randomly take any number 1–9.
  2. Check if it is safe to put in the cell.(row , column and box)
  3. If safe, place it and increment to next location and go to step 1.
  4. If not safe, then without incrementing go to step 1.
  5. Once matrix is fully filled, remove k no. of elements randomly to complete game.

Improved Solution : We can improve the solution, if we understand a pattern in this game. We can observe that all 3 x 3 matrices, which are diagonally present are independent of other 3 x 3 adjacent matrices initially, as others are empty.

(We can observe that in above matrix, the diagonal matrices are independent of other empty matrices initially). So if we fill them first, then we will only have to do box check and thus column/row check not required.

Secondly, while we fill rest of the non-diagonal elements, we will not have to use random generator, but we can fill recursively by checking 1 to 9.

Contact: “sahil242bhatiya@gmail.com”

--

--

Sahilbhatiya

I am a Software Developer with an innovative thinking sense who loves to develop high-end software with a piece of extraordinary knowledge.