Archive for June, 2006

A new Sudoku puzzle generator

Wednesday, June 7th, 2006

I’ve had to set aside the Sudoku stuff for a couple of days while I did some real work. But, George Koch has been keeping busy. George sent me a Sudoku puzzle builder that he’s been working on; he’d managed to make it work with my application. His algorithm is better than mine: where mine is pretty simple and doesn’t do key things like guarantee that a generated puzzle has a unique solution, George’s does. You can also specify difficulty of the generated puzzle. It’s a great addition to the application.

I had already done most of the work, but I spent a few minutes making it possible for the user to select the puzzle generator they want to use when they create a new puzzle. It uses the extension-point mechanism to find puzzle generators, so you just have to drop ‘generator’ plug-ins into the application and everything just works. I’ve even set it up to handle dynamically installed plug-ins; you don’t need to restart to make use of additions. This will come in very handy when I hook in the update mechanism.

I need to make sure that the legal aspects are properly managed before I commit the code into the repository and share it. I’ll let you know when that happens so you can make use of a good puzzle generator (rather than the junk I built).

Eclipse Sudoku!

Friday, June 2nd, 2006

I managed to speed up my puzzle generation algorithm by a few orders of magnitude. In the process, I got a free solver out of it. The Sudoku game is coming along quite nicely; not bad for about three days worth of actual effort.

We’ve also wrapped up the plug-in into an Eclipse RCP application, and added some fancy icons. Here’s what it looks like as an RCP application:

I’ve been playing with it a lot over the past day or so, and am quite happy with it. The one area where we really need to do a lot of work is in determining an appropriate set of given cells for a puzzle. Currently, we don’t do that very well.

The application itself is pretty function rich. You can click on a cell to set its value, or you can type the digit to put in the cell under the cursor. When you hover over a cell, it shows you the values that can legally be put into that cell based on the current state of the board (there’s no guarantee that any of those suggested values are actually in the final solution). We also added a feature (see below) where it marks the rows, columns, and boxes that are invalid.


“But,” I hear you say, “that’s cheating.” You’re right. We’re going to add some options to turn on or off the help.

The state of the current game is saved when the game is shut down, so that when you restart, it resumes with the previous state intact. It also has a cool “Solve” button that uses the fancy backtracking algorithm I developed to solve the puzzle (from its current state) in front of your eyes. If a solution is possible from the current state, it will find one (if you have invalid values in any of the cells, the solve will fail).

For kicks, I packaged up a Windows version of the RCP application. It weights in a 10MB. A little large, but not too large IMHO. I may put some effort into stripping it down.

If you want to take a look at the code, be my guest. Download and import this Team Project Set and it’ll set you up with all the code. Be advised that we’re still working on it and significant changes will likely be made. I intend to spend the next few days adding more comments and generally cleaning up the code. There’s a few spots in there that are a little inefficient in their implementation that I want to profile (with TPTP) and fix up.

I’d love to get any patches you deem valuable (I’m the only “wayne” at eclipse.org). There’s also some test projects, but they’re not included in the team project set.

There’s a few partially started bits in the code that you might find interesting. To start with, I have the puzzle generation functionality implemented as extensions. The plan is to make it possible to provide other sources of puzzles including pre-packaged ones or those generated by another algorithm or whatever. I also intend to make the solvers pluggable so that you can add other solvers and watch them in action.

At present, I don’t have a packaged up version of it for download, but do intend to shortly.

You are currently browsing the Eclipse hints, tips, and random musings weblog archives for June, 2006.

  • Pages

  • Archives

  • Categories