Browse DevX
Sign up for e-mail newsletters from DevX


Build a Sudoku Puzzle Game Generator and Solver for PocketPC : Page 4

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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

From Grid to Puzzle
After successfully generating a valid and complete Sudoku grid, the next thing is to turn it into a Sudoku puzzle by blanking some of the cells. Once again, the random number generator is your friend. The first step is to decide how many cells to turn blank. I used a random number generator to decide this:

Random rnd = new Random(); int count = rnd.Next(52, 60);

That returns a number between 52 and 60—the number of cells to turn blank. To decide which cells to turn blank, again you can turn to the random number generator:

for (int i = 0; i < count; i++) { int location = rnd.Next(0, 9); int location2 = rnd.Next(0,9); data[location, location2] = 0; }

Figure 4. Deploying the Solution: This dialog provides a list of device options for deploying the solution.
Finally, the application solves the Sudoku grid, just to ensure it's solvable, because removing numbers at random can result in a grid that doesn't have enough hints to complete.

Testing and Deployment
To review this application, you don't necessarily need a windows mobile device. Windows Mobile 5 ships with emulators for Pocket PC and Pocket PC Phone, which I used extensively during development. To deploy the application, go to the Build menu and select "Deploy Solution." You will see a dialog box similar to Figure 4 for project in your solution (unless you choose not to see the dialog by clearing the check box at the bottom of the dialog).

Choose the device type that matches the device where you want to deploy the project, or select one of the emulators.

I tested the application on both the Pocket PC Emulator and a Windows Mobile 5.0 PocketPC device, XDA Exec, manufactured by HTC. I hope this article has whetted your appetite for Smart Device development. Happy coding!

Tade Oyebode holds MSc degrees in Computing and Finance from Birkbeck College, University of London, and has written several articles for Devx. He lives in London, in the United Kingdom with his wife Kemi and works as a software developer at the Royal Bank of Canada.
Thanks for your registration, follow us on our social networks to keep up-to-date