Welcome to MSDN Blogs Sign in | Join | Help

Time for a little fun and games (Silverlight helps play Sudoku!)

I'm not much of a Sudoku player, but I was recently in the company of some and got an idea for a Silverlight application to help solve Sudoku puzzles. There are already plenty of fine Sudoku programs out there, so I didn't set out to write "the world's best Sudoku program". Rather, this was an opportunity to explore some aspects of Silverlight that I haven't shown off yet such as audio, keyboard input, control embedding, and some more animation.

Sudoku is a surprisingly complex game and its puzzles range from very easy to quite difficult. Naturally, there are a number of different techniques that can be used to solve a Sudoku puzzle. Most of the techniques rely on keeping track of what the valid candidates for each cell are. Keeping track of all the candidates is too much for most people to do in their heads, so the common approach is to maintain a collection of pencilmarks. Keeping the pencilmarks up to date is a simple, monotonous task that involves no creativity whatsoever - and is perfect for a computer!

The Silverlight Sudoku Helper displays a Sudoku puzzle, automatically tracks the valid candidates, and leaves the creative problem solving fun to the user. It also prevents illegal moves and plays some fun sounds. :) The application looks like this:

Silverlight Sudoku Helper

You can click here (or on the image above) to play a game of Sudoku in your browser. As usual, I've made the complete source code available, so click here to download the source code and play around with it yourself! (To build the project, you'll want to use Visual Studio 2008 Beta 2 and the latest Silverlight Tools.)

Notes:

  • Directions for how to use the application can be found at the bottom of the Silverlight Sudoku Helper web page.
  • The sample boards from Wikipedia and Sudopedia are included to make it easy to get started and are believed to be free of copyright restrictions.
  • I came up with the "nearly complete" sample board myself and hereby release it to the public without copyright restrictions. :)
  • There is no mechanism to automatically import boards from other sources because most of the sources I came across made a point of restricting the use of the boards they offered in one way or another. That's why it's easy to create a blank board and type in any board you want (hint: use the Shift key when typing to bold the given values).
  • The audio files were taken from the %windir%\Media directory, renamed slightly, and converted to the WMA file format for use by Silverlight. They are not included in the source code package to keep the download size small (if you download the sample code and get an error 1001/DownloadError when viewing the application, it's probably because the audio files are missing). Feel free to substitute your own favorite sounds!
  • The key handling is done on KeyUp instead of KeyDown because Silverlight does not generate KeyDown events for the arrow keys. If/when this is addressed, the key handling could be done on KeyDown instead as the more natural place (where it should automatically support holding down a key to repeat it).

I didn't know much about Sudoku when I started this project and it turned out to be a more involved game than I'd thought! I hope the Silverlight Sudoku Helper is fun and educational for others as well!

Published Tuesday, August 21, 2007 11:21 AM by Delay
Filed under:

Attachment(s): SilverlightSudokuHelper.png

Comments

# » Silverlight Sudoku Helper »  InsideMicrosoft - part of the Blog News Channel

# Silverlight helps play Sudoku

Wednesday, August 22, 2007 2:48 PM by Walter Stiers - Academic Relations Team (BeLux)

Delay's Blog has the entry Time for a little fun and games (Silverlight helps play Sudoku!)

# Silverlight helps play Sudoku

Wednesday, August 22, 2007 3:57 PM by Noticias externas

Delay's Blog has the entry Time for a little fun and games (Silverlight helps play Sudoku!)

# Silverlight Cream for August 22, 2007 - Part 2

Wednesday, August 22, 2007 7:28 PM by WynApse

Silverlight Cream for August 22, 2007 - Part 2

# re: Time for a little fun and games (Silverlight helps play Sudoku!)

Friday, August 24, 2007 5:19 PM by Evangineer

BUGBUG: If playing in Internet Explorer 7 with tabs... the ctrl-# function to italicize a guess gets nabbed by the browser.  So if you have 4 tabs open, you can't guess 1,2,3, or 4.

# re: can't guess in tabbed IE7

Friday, August 24, 2007 5:45 PM by Evangineer

After poking around a bit more, there is one more caveat.  In the example given (4 tabs open), you can't guess the numbers 1-4 is almost correct. You can guess the number of the tab displaying the SudokuHelper.

# re: Time for a little fun and games (Silverlight helps play Sudoku!)

Friday, August 24, 2007 5:50 PM by Delay

Evangineer,

Yep, I bumped into this myself during development and spent a bit of time trying to come up with a scheme that wouldn't conflict with any of the possible web browsers (no luck). Because I didn't want to get into Alt vs. Meta key issues and I'd already given Shift over to bolding the givens, Ctrl was all that was left for italicizing guesses without resorting to the F1-F9 function keys (which have their own issues). As you point out, IE7 uses Ctrl+# to switch among web page tabs, so there's a potential for conflict. The simple workaround I use is to run the Sudoku helper in its own IE window (i.e., without other tabs open). If you or others have suggestions for better key combinations, I'm happy to consider them as well. :)

# August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET

Thursday, August 30, 2007 3:41 AM by ScottGu's Blog

Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

# August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET

Thursday, August 30, 2007 3:58 AM by Elan's Aggregated Blogs

Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

# August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET

Thursday, August 30, 2007 4:07 AM by BusinessRx Reading List

Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

# August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET

Thursday, August 30, 2007 4:12 AM by ASP.NET

Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

# 数独

Thursday, August 30, 2007 7:10 AM by かるあ のメモ

August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET(ScottGu's Blog) より 面白そうなアプリケーションがいくつか紹介されていました。 いま W-ZERO3 の細い回線なのでまだダウンロードしていませんが...

# Silverlight 1.0 is out and it supports Linux

Wednesday, September 05, 2007 12:33 AM by Scott Hanselman's Computer Zen

# Silverlight 1.0 officially released

Wednesday, September 05, 2007 2:07 AM by dnknormark.net

Silverlight 1.0 officially released

# August 30th Links: ASP.NET, ASP.NET AJAX, IIS7, Visual Studio, Silverlight, .NET

Wednesday, October 03, 2007 11:02 PM by ASPInsiders

Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

# Silverlight 1.0 is out and it supports Linux

Tuesday, October 09, 2007 9:32 AM by Blogs

Wow, I didn't see this coming. ( That's a lie, I totally saw it coming and have been saying it

Anonymous comments are disabled
 
Page view tracker