Sudoku. Some people love it, and others just don't have the patience for it. Does it help ward off mental decline? Can it make you smarter? Will it help kids get better at math? Well, probably not, but it can be a lot of fun.
In Programming Sudoku, Wei-Meng Lee, founder of the software training company Developer Learning Solutions, has provided a clear and understandable guide to using the Visual Basic programming environment to produce a respectable software version of Sudoku.
Sudoku Puzzles
Sudoku is a puzzle that first rose to popularity in Japan. Now people all over the world enjoy solving Sudoku puzzles. The rules are simple--arrange the numbers 1-9 in a grid composed of a 3 x 3 array of smaller 3 x 3 grids such that each number appears only once in any small 3 x 3 grid, and only once in each of the resulting 9 rows and 9 columns.
Programming With Visual Basic
Microsoft has gone to quite a bit of trouble to create programming languages for users of all skill levels and the tools for using them. One of the easiest programming languages to learn is Visual Basic (VB), which runs on PCs and can be used to create professional looking applications. Visual Basic should not be confused with the original version of BASIC that was one of the first programming languages to be useful with personal computers back in the days of the first Apple and IBM compatible machines.
Visual Basic might not be the language of choice for professional programmers who need to developing industrial-strength, fast-running programs, but it is relatively easy to learn and is often used in colleges to introduce non-computer science majors to computer programming. Which is not to say it is not a powerful language that can do a lot of things--it can. It is a good choice for accomplishing the task of producing a Sudoku puzzle application and for gaining skill in the VB programming.
Programming Sudoku in Visual Basic
Lee has organized the book logically. After a short introduction to the rules and game play of Sudoku, he begins by explaining how to set up the basic framework of the application. This is done quite efficiently (in only 35 pages). The basic form (window), interface and controls, grid graphics and sub-procedures needed to get a simple but functional Sudoku game up and and running are covered. But, at this point it isn't a very sophisticated or interesting program.
Next he goes on to provide the greater functionality that any serious player (or programmer) would want in their Sudoku application. A basic Sudoku solving algorithm called Column, Row and Minigrid Elimination (CRME) is presented followed by more advanced methods like "lone ranger" and "twins", "triplets", and "brute force elimination". Lee finishes up with the more challenging task of creating a way to generate solvable puzzles of varying difficulty.
All the necessary code is presented in the text and is also available as a download from the publisher's website. It would be a shallow approach indeed to simply download all the code and paste it into the VB environment. Much more will be gained by entering the code by hand to fully understand what it does. Mistakes will invariably be made, but this is a valuable part of the learning process.
The book is a little light on explanation when it comes to the functions and sub-routines. They need to be studied before they can be fully understood. Novice VB programmers will just have to accept Lee's work at face value until they spend some time really getting into the code.
Beginning programmers will do well to go through a good VB tutorial before tackling the project presented in Programming Sudoku. Those with more experience can safely dive right in. Programmers who are familiar with C# should have no trouble building this this project in VB or making the necessary modifications to create it in C#. Experienced programmers should also be able to understand Lee's presentation well enough to adapt the code examples to other languages such as Java or C++.
The book was written for use with Visual Basic 2005, but most of the code should work in later versions of VB. If it doesn't, figuring out how to fix it will also provide an invaluable learning experience.
References
Lee, Wei-Meng; Programming Sudoku; Berkeley, CA: Apress, 2006
Join the Conversation