Whist Card Game in C# and WPF

Greetings all, I am hopefully going to have some time over the next few weeks as my current project at work ramps down and I await the next one. I have begun a new side project to use some of this time toward and plan to make a few posts about it. I am writing a card game, which might seem cliché, but it is something I have always wanted to do and it is going to be a game that you don’t see very often.

I like cards and I play both bridge and whist whenever I get a chance, which is not very often. It is hard to find people to play and consequently I want a computer game to play. I am going to start with a base solitaire game for Silverlight [thanks to Eric Guo] that has a decent card and deck class that make it easy to quickly show the cards on the screen. I have put together a quick starter application that has a nice felt background and that will deal the cards out and I just added sorting, as one would for bridge, but with uptown and downtown (hi/lo) options for sorting both ways for Bid Whist hands.

The key feature will be the Artificial Intelligence component that will play the other three hands. This is not a simple task and is certainly where the challenge lies. My first attempt will likely use more heuristics than anything, a rule based player. It will certainly be a work in progress for a long time to come. I will publish to my as soon as I set it up. For now here is a screenshot of what I have:

Deal and sort for Whist hand…

One thing I want to note is how I solved the problem of converting the Silverlight xaml I got from the sample project into WPF xaml that would run. The problem that occurred in multiple places and in almost all animations, such as just moving a card was the same. The Silverlight application had code for nice move animations and a nice flip animation that I am planning to reuse. But, in WPF you must have a valid, preset Top and Left value on the item you wish to manipulate. This is not so in Silverlight and causes a common NaN error. The answer I found at and showed me how to get a rendered top and left value. Instead of using:
var dx = Canvas.GetLeft(deck);
var dy = CanvasGetTop(deck);

which will result in a NaN error if you try to use the value returned. You have to use:
var offset = VisualTreeHelper.GetOffset(deck);
var dx = offset.X;
var dy = offset.Y;

This GetOffset method will give you the rendered positional values for your element.

Still Walkin’

Yes I am posting again. I refuse to give up on my blog. I have been away from my hometown and my work for the last year and a half or so and I am now back and getting back into my routine. Much to my joy as I have missed all these things tremendously. I am back to work at GloryKidd Technologies and happy to have the opportunity.

Reminded daily why I have always loved Louisville. I am back in my old neighborhood Starbucks, clacking away. Hope to be able to post some new articles soon as I see where my new project takes me in the world of coding.

Yes I am Still Here

I am working from home, thru my Elusive Development company, on a side project to develop a windows forms app with several components.

It is a very interesting project so far, but I am only a couple of weeks in to it. In the end it will be a couple of windows forms apps. One for the client and one for the end user, as well as a windows service that will handle timing and the win32 api calls. The service will use the api to create a new desktop and then create a process w/in that desktop and switch to it, effectively taking over the users computer with the new desktop. The user is ultimately forced to deal with the, now in the foreground, application in order to get back to what they were originally doing. Pretty sweet. I am building it using C# for the 2.0 framework. I opted for 2.0 versus 3.5 in order to prevent requiring the user to have 3.5 installed. As folks get the 2.0 framework w/sp3 for xp, I am pretty much guaranteed my target platform for that os on up to windows 7.

For those interested I am using a plugin archictecture that utilizes the Abstract Factory and Template Method design patterns so far. Dll assemblies with new types and usercontrols for those types are loaded at runtime and instantiated using factories. Neato…

A Brief Note…

This will be a brief post.  For one, I did want to post something because I haven’t in a while and I need to write another decent article.  In fact I have the notes and outline for a post about the work I have been doing in jQuery lately.  I have been writing plugins, a couple at least, for work, for our public facing site.  One rather large one in fact, to build an image gallery from an un-ordered list of image/thumbnail links, that allows zooming in and out and dragging of the zoomed image around in the view pane.  I will post about it soon.

I have also been studying an average of two hours per night in Ruby and Ruby on Rails.  My position at Glorykidd Technologies as a senior software engineer has afforded me a rare opportunity to work on a large scale project in rails and I am studying for that purpose.  I am quite excited to actually get to work on a real project in rails.  More to come about this as well. But for now I am just claiming my blog on my Technorati Profile so that it will show up there.  I have been using delicious a whole lot lately, as opposed to Google Bookmarks and I like it very much.  And, along those lines I am trying out Technorati as well… J

No really this time I mean it

I am going to try to keep up my blog again.  But, this time I am going to use a wordpress.com blog instead of my own domain.  I am tired of putting it up and then letting it expire and then forgetting to renew and then having to repurchase my domain and set the site up again.  With wordpress.com I don’t have to worry about it, it is just there.  Granted, I don’t have the ability to put up other content, development wise, but wordpress is pretty powerfull, and as far as online publishing of my written content, anything I would produce, I can pretty much count on the fact that I can use wordpress to put it up.

So, here we go again.  This is me back at a new job and back with a new blog.  Yeah!!!

Cool stuff I am looking at now…

1. Azure
3. jQuery
4. Zoho