Browse DevX
Sign up for e-mail newsletters from DevX


Build a Sudoku Puzzle Game Generator and Solver for PocketPC

Not only can you generate your own Sudoku puzzles with this mobile application, but you can solve them, too—even puzzles you enter from newspapers or books.

he Sudoku game is the latest craze in the UK, and it's become so popular that every major newspaper now publishes puzzles with varying difficulty levels. I've found the process of solving Sudoku puzzles fascinating ever since I first saw one in the London Evening Standard newspaper. But after solving a few, I decided it would be even more interesting to write an application capable of both generating and solving Sudoku puzzles. In this article you'll see how to use Windows Mobile 5.0 and Visual Studio 2005 to create such an application.

Sudoku originated in Japan. The name is is an abbreviation for a Japanese expression that translates to "The digit must remain single."

There are many Sudoku variants, but by far the most popular is a 9 x 9 grid, divided into 3 x 3 regions. The grid is partially filled with the numbers 1 to 9. The challenge is to complete the remaining cells in such a way that:

Figure 1. New Project Dialog: The figure shows the process of creating a new PocketPC Project in Visual Studio 2005 with Windows Mobile 5 installed.
  • Every row contains a number in the range 1 to 9, each number occurring once.
  • Every column contains a number in the range 1 to 9, each number occurring once.
  • Every 3 x 3 region contains a number in the range 1 to 9, each number occurring once.
Creating a Windows Mobile 5 Project
I assume you have already installed Visual Studio 2005, and also downloaded Windows Mobile 5.0. If you haven't downloaded Windows Mobile 5, you should download it now, if you want to follow along with the article or run the downloadable code.

Author's Note: I developed this project on Visual Studio 2005 Beta 2.

Figure 2. Sudoku Solver: The figure shows a finished version of the Sudoku Solver project running on a PocketPC.
After downloading and installing Windows Mobile 5, you'll see several new items in the New Project dialog. To begin, create a new Windows Mobile Smart Device project (see Figure 1).

Choose the Device Application template, name the new project "SudokuGUI," and select a project location.

Next, add a second Smart Device project to your application. This time, choose the Class Library project template and name the new project "Solver." Solver contains all the logic for generating and solving Sudoku grids while the SudokuGUI project focuses mainly on the user interface—displaying the puzzle and accepting input. Figure 2 shows a running version of the SudokuGUI project.

Loading the Sudoku Solver Project
It's worth your time to test-drive the finished Sudoku Solver project before digging into the code. To do that, extract all the files in the downloadable zip file to a directory of your choice and open the solution file SudokuUI.sln located in the SudokuUI folder.

Thanks for your registration, follow us on our social networks to keep up-to-date