I’m a Sudoku addict. My love for Sudoku has most certainly surpassed unhealthy levels. Naturally, being a developer I at one point had an interest in developing my own Sudoku game just to see what it entails.
The concept of Sudoku is a very ancient one but the game’s recent popularity is attributed to the company NIKOLI which owns the copyright to the word “Sudoku” and the Japanese “数独” (lit: “number alone”) within Japan.
Game concepts, in and of themselves, cannot be copyrighted and to get around any copyright disputes I considered calling my game “9 Lives” and varying the gameplay enough by employing a strict rule of allowing up to 9 mistakes before the player loses. Essentially I was interested in making a Sudoku game for pros (no hints or anything).
However, I later learned through the Quinn/Tetris debacle that even though game concepts cannot be copyrighted, the owners of such games still show their legal fangs if you encroach on their territory and considering that my presence here in Japan is also where NIKOLI is based I reconsidered developing my own game.
That was 5 years ago, when I was just beginning to learn Objective C and OS X development. While cleaning some things up on my Mac I recently rediscovered my old Sudoku board generator code and it feels like a waste to just let it sit there unused. Instead I decided to rewrite it (the original code is too embarassing to release) and donate it to others interested in making their own Sudoku games.
Most of the Sudoku games I have played only offer pregenerated boards. My code creates random ones each and every time. As such it depends on a random number generator, in this case my JFRandom utility class which is available on github.
If you are outside Japan and interested in making your own sudoku game check out my Sudoku Board Generator.
How To Use It
This one line is all you need to generate a random Sudoku board…
SudokuBoard *board = [SudokuBoardGenerator generate];
Outputting the resulting Sudoku board with NSLog will show the board in full like below…
7 1 8 5 4 3 6 2 9
6 9 3 2 1 8 5 7 4
5 4 2 9 7 6 3 1 8
4 3 5 7 9 1 8 6 2
1 6 7 8 3 2 4 9 5
2 8 9 4 6 5 7 3 1
8 5 1 6 2 7 9 4 3
9 2 6 3 5 4 1 8 7
3 7 4 1 8 9 2 5 6
The board exposes 9 sectors (3×3 grid) and the numbers contained within for you to display in your game. That’s all there is to it. The details are all abstracted away from you. If you have any questions please don’t hesitate to contact me at jay [AT] this domain.