Sudoku Toy redux - using C# DancingLinks Engine

A while back I posted a toy app that generates (and optionally solves) a Sudoku puzzle.  It was under the rubric of Interop because the inner engine of this toy used an implementation of the Dancing Links engine for Sudoku, built in Java.  The original Dancing Links algorithm was proposed by Donald Knuth;  I found a Java engine that produced a string representation of a valid puzzle.  I hooked that engine up to an Acrobat-generation library, the Acrobat ActiveX control from Adobe Acrobat v5, all stitched together into a Winforms app built in C#. That's a lot of interop. 

The toy worked, but it had some challenges.  First, Adobe was apparently discouraging use of the Acrobat ActiveX control.  It was available in Acrobat v5 but them removed from subsequent releases of Acrobat reader.  So in order to install and use this toy, you had to go get an old code base, one which had several known security problems. That was one problem.  Also Acrobat v5 did not install alongside Acrobat v6, 7, or now, 8.  So anyone that already had a current or recent Acrobat  Reader, couldn't use this toy.  Also, the hassle of installation was a problem in general.

XBAP to the rescue!  I revisited the Sudoku puzzle generator, and now I have a new version.  It is an XBAP, based on WPF, and runs in the IE browser.  No more Acrobat requirement.  No more unsupported ActiveX controls.  The use of WPF within this app is pretty mundane - I just create a table with WPF.  It uses the same Dancing Links engine code, but I ported it from Java to C#, in order to avoid the use of the discontinued J# compiler.  It was a very straightforward port, and there were no problems whatever.  I didn't even use the JLCA, I just hand-ported it with judicious use of search-and-replace. 

This is an interop blog, right?  So where is the interop now?  This is a C# app, using WPF, and it runs in IE.   With all that, it's hard for me to call this interop. At best it is re-use of an existing Java-based asset, but I did have to convert the Java logic to C# .  But it's an update to an older post, so I thought y'all wouldn't mind if I put it here.

Anyway, try it out.   In order to run this, you need IE7.  Also, if you don't have the .NET Framework v3.0 installed on your machine, you will get it if you run this app.  That download can be a drag!!  You have been warned.

Some notes

How did I build the WPF part?  Well the WPF itself, as I said, is nothing to write home about.  WPF can do some amazing things with dynamnic graphics and animation, but this app doesn't do those fancy things. Basically this is WPF generating a table at runtime.  I built all the XAML code by hand using a text editor.  I've included the code here as an attachment for those who want to check it out.

Also - just to be clear - this is a puzzle generator, not a puzzle app.  I use it to generate puzzles, which I then print out, and solve.  I don't like to solve Sudoku on the computer, I prefer to do it on paper (tree hater).  So the app here just creates a new puzzle.  If you want to click on a puzzle and try to enter numbers to solve the puzzle yourself, this app will not help you. 

Also, the app only solves Sudoku puzzles that it generates. you cannot insert arbitrary sudoku puzzles in and ask for a solution.  maybe that is for another day.

Given that Silverlight is out, and we have Expression Blend and so on, it seems like I ought to produce a Silverlight version of this thing.  That is on my list for later!  By the way, if anyone else wants to build a Sudoku App, the C# DancingLinks engine contained in this project is a good piece of re-usable infrastructure.  If you do grab that part of the project, let me know, I'm interested in hearing how you are using it.

Cheers!

 

XbapSudokuGeneratorProject.zip