Saturday, March 28, 2009

How to make Asymmetrical Board Game maps in Silverlight

Or, how I spent my evenings at MIX09 in Las Vegas.

Last year, I began looking into writing board games with an asymmetrical map boards. I started with Awful Green Things from Outer Space (AGTFOS), a classic beer and pretzels game by Tom Wham. I started with an alternate game board graphic I downloaded from

But, since the map is asymmetrical, there is no simple math function that, given an X,Y coordinate, would tell me what room in the spaceship I clicked on.

After a lot of googling, I found that boardgame programmers use a 2D array where every every element in the array corresponds to a pixel in the map image. Then set al the array elements to values that equal what room that pixel is in. This worked great, but it has a problem - No scaling. I could not scale the graphic and still know what room I was in.

WPF and Silverlight to the rescue!

So, as a proof of concept, I took a states map of the USA in SVG from Wikipedia and used ZamlTune to convert the SVG to XAML. Since all the elements in WPF are scalable and clickable, I was able to, with just a few lines of code, make the map aware of what element I was clicking and change its fill color.

That solved half of the problem of a asymmetrical board game map. The other issue is for movement and conflict. We need to know what states directly border the selected state. For this we need to go back to Comp Sci 350 - Data Structures. We need a graph.

Graphs have Vertexes and Edges. A vertex can be thought of as a location and the Edges as the roads to and from these locations. So, if we had a Graph with a vertex for each State and an edge to each bordering State, we could easily find out what States border each other.

Unlike previous silverlight examples I've posted, this one cannot be embeded since it needs to resize, so you need to open the link to run my example USA map. If we wanted to play Risk on a USA map, this would be a large positive step towards that goal.

As, you can see in the image the selected State is in Blue and the bordering States are in Light Blue. (Click on Image to Open The Silverlight Application)

Unfortunately the Graph object I wrote for this proof of concept is not nearly as full featured a Graph object as per my previous post.

And here is a zip file containing the entire Visual Studio 2008 Project.

Saturday, March 21, 2009

Why MIX09 was a success!

After a shaky start with their pre-conference workshops, the actual conference was fantastic.

All four of the Keynotes were fantastic - and quite motivating.

Unlike other conferences I've attended where the entire content is based on future, unusable at work, new products. Or, they all seem to be doing nothing but promoting their book. Well, MIX09 was, of course, a little of both of those, but it was also so much more.

There was a lot of "soft" information for the designer on the UX or User Experience. Since I am mostly a backend developer, I gained a lot of insite on the design side. There was also quite a bit of information on silverlight - including animation.

So, all in all, for me MIX09 was an unqualified success.

Tuesday, March 17, 2009

First impressions from MIX09

Well, I'll been here in Las Vegas for 36 hours and I'd just like to say that I've never stayed at a hotel where the employees are as helpful and pleasant as here at the Venetian.

The first session of the pre-conference was fantastic: Semantic HTML and Unobtrusive JavaScript presented by Nate Koechley

The second session, on the other hand, Cascading Stylesheets presented by Molly Holzschlag was atrocious. After the first two hours, we had covered what anyone can learn about CSS from a book in the first ten pages. Quite a few attendees, including my team, left the presentation early. (Hint Molly, you do not need to repeat war stories more than six or seven times)

So, with the main conference starting tomorrow, MIX09 is batting 50%.

Monday, March 9, 2009

The "Weekly" Newsgroup post #1

When I decided to become more active in the dot net community, I did a number of things:

I started this blog,
I started to attend the monthly meetings of our local users group ( )
I started writing articles for (None of which I've finished yet - Bad Lee)

And, I started to hang out in the C# and newsgroups as well as the forums at and in the hope that with my feeble knowledge I could help someone that the more experienced and knowledgeable would pass over as not worth their time.

Well, first thing I learned was that all the "Experts" on these newsgroups/forums are so helpful that I was only able to help a few people, and only then because their questions dovetailed exactly into my knowledge base.

But the big thing I learned was home much I could learn by reading the posted questions and answers. People are out there trying to do things with Dot Net that I never even thought of trying and reading in the replies how achieve those things has expanded my knowledge of all things Dot Net.

I used to think (and still do) that reading others source code was a great way to learn. When I found a link to Scott Hanselman's Weekly Source Code blog entries, I was forever indebted to Scott for searching the web and finding those few source code gems in the vast sea that is the Web.

I the same vein as Scott's Weekly Source Code posts, I'd like to start a "Weekly" posting of one or more Newsgroup/Forum questions that really deserve more focus than they received.

And Now: Question of the Week #1
is there shorter way to code this

In this series of questions and answers, rodchar asks how he can get to two properties (Id and Text) of three different controls. His example shows the brute force way of taking an Object and through a series of IF statements determining if the Object "IS" of a certain type, then casting it to that type so as to access its ID and Text properties.

On reading the answers the Experts gave, it is obviously a perfect problem to be solved by an Interface. I chose this question because in my dealings with other programmers, Interfaces are the hardest part of OOP for them to grasp. Here in this one simple question, we have nearly the perfect example of how and where to use an interface.

Since there is now common parent that exposes the Text property, rodchar cannot just cast the Object to the parent. But, since they all already implement a Text property and an Id property, we can define an Interface that declares these two properties.

Here is the Interface suggested by DabblerNL

public interface ITextAndID 
string Text {get;set;}
string ID{get;set;}

Now, All that is needed is to have the Objects implement the interface. Since they technically have already done so, they only need to be declared.

public class InterfacedTextBox: TextBox, ITextAndID {} 
public class InterfacedCheckBox: CheckBox, ITextAndID {}

And viola! Just replace your old TextBox and CheckBox with the new versions and then all you need to do is cast the new controls "AS" your new interface: ITextAndID as so!

var TheId = (ITextAndID)TheObject).ID;
var TheText = (ITextAndID)TheObject).Text;

Being able to access these properties through the interface, and being able to implement the interface with no actual code other than the declarations makes this a pure example of interfaces!

Sunday, March 1, 2009

Sudoku in Silverlight

You know how it is, you learn a skill (Programming in my case) because you see the results of others. Looking at the fruits of their labors, you say, "wow! I want to be able to do that." So you start learning, take some classes, read some books, maybe like me you enroll in the Computer Science program. If you get good, you may even get a job using your new found skill. But, did the learning of this skill lead you to the place you wanted to be, all those long years ago?

When I first started programming, it was to automate the games I was already playing. Then I moved into trying to replicate the types of games that I had played before on the computer. But as it usually happens, the real world got in the way. Instead of learning how to animate sprites, I had to learn how to connect to a database. Instead of graphics, I had to learn about algorithms.

Now, I'm not knocking my job and the work I do. I rarely go to "Work" since I get to indulge in my passion for programming every day. But, I feel this need to give more than lip service to the original reason that I got into the "Biz" in the first place.

Believe me, in 25 years the landscape of game programming has changed so much that I hardly recognize it! And, I've tried to keep my feet wet in the technology the entire time. The time when the ability to draw a digital stick figure and write a great game around it (Lode Runner) is long gone. When I first made up my mind to bite the bullet and truly try to learn game programming, in depth, the technology seemed so complicated that I almost quit.

But Rome was not built in a day and neither were any of my favorite games. Like I tell all of my junior programmers, "Start at the beginning, then just program each little piece until it is done”, I decided to start with the smallest bite I could “chew” and then just keep going. The first "Game" I wrote was a Sudoku generator with a Javascript back end. I Wrapped a website around it and launched it a couple of years ago.

Well, here is the thing about games, the are not all created equal. Sure Sudoku is a "Game" per se, but not really related to my true love, boardgames. So languished for a few years without any upkeep. I even thought of just shutting it down, but according to Google analytics, I have a few very loyal customers. And, now with the new technology of Silverlight, I thought that updating my site with a Silverlight implementation of Sudoku would help me build my skills and give a tech boost.

Well, here is my take on Sudoku in Silverlight.

And here is a zip file containing the entire Visual Studio 2008 Project.