Klondike Solitaire

"So you are saying that here are two commonly played versions of Klondike Solitaire?" the young programmer states, or maybe asks.

I nod my head.

"My friend told me that there are hundreds!" states the young programmer.

I pause and wonder how to deal with junior.

"There are many different types of Solitaire, of which Klondike Solitaire is but one. There are however two commonly played versions. The Alpha versions with a one card deal, and the beta version with a two card deal".

The penny drops.

"And that is why we the Options allowing a one or three card deal" elaborates the young programmer, pleased with himself.

I ponder inwardly whether the young programmer owns a set of real playing cards, as he ponders aloud what is the point of allowing one and three card deals.

A picture is worth a thousand words, and as the boss is currently on a marketing junket of some kind, and the office is ours, I reach for a deck of cards.

I shuffle the deck and start to deal. The first card is placed face up followed by another six cards face down. I place the second, again face up, on the second column followed by another five cards and so on.

The young programmer stares transfixed. I am right. He has never seen a real deck of playing cards.

As I place the Stock above the first card, I explain that the method of placing the cards isn't important. I could just as easily placed them in columns.

"And now we can begin."

Fortuitously, the first card put down was the red Ace of hearts, and so I picked it up and placed it above the Tableau, explaining as I did so.

"The Tableau does what exactly",asked the young programmer.

I searched for a metaphor that he might undestand.

"The Tableau doesn't do anything. Consider it a sequence of lists ordered by in a decreasing sequence, ideally starting from the King and finishing with an Ace. Furthemore, the sequence alternates in colour."

Being an old school programmer, I still use arrays, and lack the language to describe fancy data structures. Never-the-less, I saw a glimmer of understanding in the young programmers eyes, as he looked at me scathingly and announed:

"It would be more efficient to use an ordered list class paradigm of some kind, to allow extensibility, make the code more understandable and it should have at the very least some kind of separation between data and code."

"You could start with a card class."

I looked at him.

"If I may continue, the Tableau contains or with luck and skill will contain cards in the described order. For example, a black Six, may be placed on a red Seven, or A red Queen may be placed on a black King."

At this point, the young programmer speaks:

"What about the Ace? How does that fit into the rules described. Why has it been placed on the top bit?"

"The 'top bits' are called the Foundations. In Klondike Solitaire (whether you are playing one turn or three turns), the Foundations have to start with an Ace."

"And that is why, you can see four faded Aces at the top of the screen".

We both pause and look at the screen. There are indeed four Aces. Faded.

"An Ace is on the Foundation. There is a Two of Hearts on the Tableau. There is a space in the Tableau." expounds the young programmer while his hand hovers over the cards.

I don't know if this is because he is unused to interacting with the physical world, or whether he still unsure of the rules of Klondike.

I explain:

"The Two of Hearts can be moved from the Tableau and placed on the Ace on the Foundations. Cards on the Foundations must follow suit and be in ascending order."

The young programmer looks at me triumphantly, moving the card and at the same time, gloating:

"If you had used classes, the Foundations and Tableau could have used the same code. You coded them differently. I looked at the code."

Sometimes, silence is the best response, and I remain silent until the young programmer, realised that he doesn't know what to do next.

I consider telling him to look at the FAQ, relent and tell him.

"The Stock is there to be used. We are playing the one turn Klondike solitaire, so take one card from the Stock, turn it over, and place it in a new pile next to the Stock."

The young programmer does so, and I can tell from his facial expression, that he is trying not to mention something to do with card classes and the Stock pile.

The card is a King.

"Only Kings can be placed in an empty position on the Foundation. Any other card, can only be placed on ..."

"... a card of alternate colour in a numerically decreasing sequence from King to Ace" finished the young programmer for me.

I almost smile. And then I remember the uncalled for comments about card classes and don't.

The Young programmer, slowly at first as he gains confidence in interacting with the real world, moves cards around the Tableau. A row becomes empty and a King of Clubs is placed in the empty position. He deals another card from the Stock, and so it goes.

The Young programmer is quiet, too quiet. Eventually I'm forced to ask him what is on his mind. He responds with:

"How do you know when you have won a game of Solitaire?"

I tell him, that once all cards are placed on the Foundations, in ascending sequence and suit from Ace to King that the game is won.

"I know", he tells me, "but how do you know what your score is. How can you win a game without a score?"

"Whether that be one or three card Klondike", he continues, mimicking my earlier explanation.

"It has an Undo feature. It has options. Why doesn't it have a score?"

"And how does scoring in Solitaire (Klondike specifically) work anyway?"

I start to explain.

Scoring on KlondikeSolitaire.Day (one turn)

"There are various scoring systems in Solitaire, and the one that we can use now (so you know if you have won) is as used in the Microsoft Windows Solitaire version of Klondike".

"Turning over a Tableau card gains five points."

"Moving a card from Waste to Tableau gains five points."

"Moving a card from Waste to Foundation gains ten points."

"Moving a card from Foundation to Tableau loses fifteen points."

"Moving a card from Tableau to Foundation gains ten points."

"Recycling the waste when playing Solitaire turn one subtracts one hundred points"

The Young programmer observes that the scoring system seems arbitrary to him, which indeed it is, and asks for clarification of the term 'Recycling the Waste'. In reality, he mumbles something like 'wass at?'.

"Recycling the waste simply means dealing all the cards from the Stock pile to the Waste pile, and starting again."

I anticipate the next question and so answer it before he can ask.

"Yes. There will be scoring on KlondikeSolitaire.Day".

And for a few moments, silence reigns, and I turn to my computer and think about how to add scoring to my code, which wasn't designed to accomodate such a feature.

The peace and quiet is short-lived.

Scoring on KlondikeSolitaire.Day (three turn)

As I am wrestling and deep in though with the thorny problem of adding scoring, I become aware of a buzzing sound, and leaving the zone and focussing hear:

"How does scoring on three turn Solitaire work?"

I sigh.

"The rules are identical, or in this game will be identical for both versions of Klondike."

"There is however one difference. Remember that one hundred points are lost in one deal Solitaire each time that the Waste is recycled?"

The young programmer nods his assent, having so recently fallen foul of this rule.

"Remember also that the difference between the two games is solely the number of cards dealt from the Stock to the Waste pile?"

Again he nods.

"And so, it takes three times as long for the player to have moved through all the cards in Klondike Solitaire turn 3 compared to Klondike Solitaire turn 1."

Once more he nods.

"And so, to try and match the scoring between the two games, the player only loses one hundred points after the pack has been recyled three times."

The young programmer digests this asking "Is this the same in Microsoft Klondike?"

"Maybe", I say "or maybe not. Perhaps you could do something useful and play a game of Solitaire on a Windows machine so we can ascertain the facts?"

He didn't, being a Mac user, and so the answer remains unknown to me.

The Stock in Klondike Solitaire

And this leads us, before long (via data structures) onto the number of times that the Stock can be recycled.

"The Stock", I expounded, and I was expounding not merely explaining "and number of times it can be recycled is a key factor is determining the enjoyment or otherwise when playing Klondike Solitaire."

"In some versions of Klondike, the Stock can only be recycled once!"

I saw the young programmer recoil in horror at this.

"In others, the Stock can be recycled twice."

"And in yet others, the Stock can be recycled as many times as you so desire."

"If we aim to enjoy the game, which we do, and if we want to reduce some of the irritation of losing to frequently, which we do, it is of benefit to allow the Stock to be recycled ad infinitum."

And once more silence reigned.