Sudoku Part 1
What is this about
I am quite fond of Sudoku as a quick past-time that helps my brain disconnect a bit and refocus. I have apps on my phone and on my PC that I can fire up when I feel like it. Only there is a caveat, there are some variations on Sudoku such as Chess Sudoku and Killer Sudoku and I haven’t really found one app that contains all which means having to pay for multiple apps.
This got me thinking, how hard could it be to program the backend for one of these?
You can follow along in the git repo here: https://github.com/Wallyza/sudoku
I’ll try and tag specific points of interest as I go along and document them on the blog here.
The rules
Sudoku is quite simple, you are presented with a 9 x 9 grid, which is divided into 9 smaller 3 x 3 grids. We’ll call the overall grid the 9-grid and the smaller ones 3-grids.
To complete a puzzle, you must fill numbers from 1 to 9 into each spot on the 9-grid. The catch is that no number can be repeated in a row or in a column. A further trap is that no number can be repeated in a 3-grid. To sum up:
- No number can repeat in a row on the 9-grid.
- No number can repeat in a column on the 9-grid.
- No number can repeat in a 3-grid.
To get you started the grid will be pre-filled with some numbers.
As an added rule for us, the creators of a puzzle: A puzzle should have only 1 unique solution.
This is quite an important one. The way I see us generating a puzzle would be to first create a grid filled with the numbers as specified above. This should also eliminate the potential of the solver having to guess any numbers. I hate guessing in puzzle games.
Next up we’ll remove some of those numbers. The more we remove, the more difficult the puzzle becomes, but if you remove too many the puzzle might become ambiguous with multiple solutions.
This simply means that after each number is removed we’ll have to check the puzzle for a unique solution.
Roadmap
The roadmap for the app is quite simple:
- Get a basic backend up that creates a puzzle with a unique solution.
- Allow the difficulty of generated puzzles to be adjusted.
- Extract this all into a library.
- Simple web frontend that interacts with the library.
- Look at creating a frontend in Unity so I can install it on my phone as well.
Conclusion
The roadmap is oversimplifying things but the beauty of the project is that this will all require fairly basic programming but some clever algorithmic thinking behind it.
Should be fun! I’ll put part 2 up hopefully before the end of the week which will dive into the first bit of code.