Rediscovering Solitaire



REDISCOVERING SOLITAIRE

What goes into winning this game??

The first thing that comes to the mind when one thinks about solitaire is "that silly windows game where you have to form sequences of cards based on their suits".

Well, that's the basic idea of the game, but thereís lots more to this than just

Start Menu->All Programs->Games->Solitaire (Assuming Windows XP).

I am going to stick to the simplest possible version of this game and assume that there is no scoring system and also that this relates to the default settings on the Solitaire (Windows) game. There are also facts that I have compiled from a few references. Also, not all things are perfectly true because there are a few conclusions that have been derived by observing the general nature of the game.

What is this game all about?

This is basically a single player game where one tries to arrange all the 52 cards(13*4) into 4 groups (one for each of the suits-hearts, diamonds, clubs and spades) of 13 cards each, such that each group comprises of a single suit and the cards within each group are arranged in an ascending order (ace,two,ÖÖÖ..,king).

One starts off with 7 open cards such that the níth open card has (n-1) closed (hidden from the player) cards under it. This accounts for 28 cards. The remaining are kept in a group of 24(8 collections of 3 cards each) hidden cards, from which you can draw cards (all 3 cards of a collection are visible, but only the top card is allowed for drawing) when you require.

Moving an open card over another is possible only if the cards involved are of oppositely colored (Hearts and Diamonds-RED; Spades and Clubs-BLACK) suits and if the cards differ by exactly one rank. In that case, you can move the lower ranked card onto the higher one. You can also similarly move a group of cards onto a card if all lower cards below the card in the group that heads it, are in the arranged order as mentioned above.

 

Conventions used

I would like to have a few notations defined here for ease of explanation.

column:- one of those 7 open cardsí pile and it might be empty, have "open cards" or also "hidden cards" (those placed faced-down below the open ones).

stack:- the group of 24 cards will be referred to as "stack"

triplet:- any collection of three cards in the stack

foundation:- any of the four (one for each suit) final piles to which all cards of that suit are to be moved in ascending order.

The strategy

There might be many possible strategies of going about this game.

We shall look for all possible things we can do in a given move (priority-wise)and just repeat the steps till we win or till there are no more possible legal moves left.

Use the stack. That is, uncover the first triplet from the stack so that you have another "open card " to make your future moves.

The next thing is to move any open ace from the columns to its respective

foundation. If there are no open aces in the columns, try the open card at the stack.

This is done so that we can have another card (the one below the ace) to play the game with or, if we are lucky, an open column to utilize later on.

3. Try and look for vacant columns. We could keep track of this by having a boolean

which indicates whether or not a column is empty or have an int variable to indicate

how many vacant columns are there. This helps to decide further moves by expanding

the scope of moves.

Whenever one has a choice where two cards of same rank and/or suit are open, play

the one which will make it easier to uncover any hidden cards that are there at the

bottom of the columns.

4. Next, try moving columns onto other columns. This should be done only if it frees the

hidden cards (if present) under that column. If you canít directly uncover the hidden

card by moving the column but even if you can adequately reduce the distance to that

card, then do it.

One can use an "if" condition to check whether the moving of a card on another is

compatible with the rules or not. That is, whether they are of oppositely colored suits

and if so, whether they are of consecutive ranks. This should handle the algorithm for

the step of moving a card over another. You can encapsulate all this algo into a

method, say "checkmove (destination card)".

If there are columns with no hidden cards under it, move it only if there is a king

waiting to occupy its position (you can check with the boolean variable that holds the

result for the waiting of a king, as declared before).

This step is performed to free up the hidden cards behind the columns.

5. Next, one can start looking at the open card at the stack. If you can move that card onto

any other open card in your columns and if it does allow for future moves which will

uncover hidden cards, only then must you proceed. If the open card at the stack doesnít

satisfy these conditions, try another triplet from the stack.

Devising an algo which will look into whether a move allows for further moves

would be a very tedious and involving task, so lets leave that for now. To check

whether the open stack card can be moved onto any other card, one can simply use

the "check move" method defined above, by calling it on the open stack card.

6. The only other major move left is moving an open card (either column or deck; priority

given to column and that too one that will help uncover hidden cards more quickly) to

its foundation deck if possible. To check for compatibility, one can simply use an "if"

condition that checks whether the foundation deck corresponding to the suit of the

card in question has the card just below the rank of the card we want to move.

There is a lot of caution to be exercised here. This is a very sensitive move.

You see, once you move a card into the foundation deck, it canít be recovered. So it is

kind of lost to the player. What happens because of this is that the cards that could

have been moved onto it will now have to look for some other estimation card. Also, if

both cards of same rank and color are lost to the foundation decks and lower ranked

card of opposite color is still in the game, it can not be moved onto any other

card. So, it restricts a number of moves, perhaps even vital game winning moves.

What one must do is to check whether the cards (of opposite color and one less rank)

that can be moved onto the card in question are already in their respective

foundations or not. If they are, one can easily move the card in question into its

foundation deck if possible. That is the reason why aces can be discarded to their

respective foundations without taking any caution cause there are no cards that can

be moved onto aces!!

For this step, the following algo can be utilized (assuming card1 is the "open" card to

be moved and suit1,colour1 and rank1 are its respective datas).

- check whether the foundation deck of suit1 is filled upto rank = (rank1 Ė 1) or not.

- if yes, then check whether the foundation decks of suits with color other than

colour1 are filled upto rank >= (rank1 Ė 1) or not.

- if yes, then move card1 onto its foundation deck.

- if no, check if the foundation deck of color = colour1 but suit != suit1(that

is, the other suit of same color as colour1) has cards upto rank >= rank1 or

not.

- if no, then move card1 to its destination deck.

-end.

The last part of this algo is something that one can debate upon. What it actually does

is it checks if there exists on the game another card which can take its place when it

comes to moving a card on itself. That is, it checks if there exists on the game, that

card which has the same rank and color as this but is of some other suit. If it does

exist, then we can use that card when it comes to moving a lower card onto it. This

might complicate matters but if there are no other moves left, this is an open option.

7. If none of the above steps can be executed, well then, my friend, we will have to deal

again. It is not necessary that every game of solitaire can be won. If you look on the

web, the most general answer you get is "one of every 4-5 solitaire games can be

won!!".

So, there exist such deals in solitaire which canít be won too!!.

(for a full program on the above procedure, please check out http://www.fastgraph.com/player.html )

Tricks

Now, this completes the major strategy of this game. There are other complex strategies that exist, but I will mention only a few over here.

Ť whenever faced with a possibility of steps, use that which will uncover any or most of the hidden cards. This can be done by comparing the number of hidden cards below the columns that are in question.

Ť always try out all the cards in the deck before making a move, since they might contain cards that will help you make a move of greater priority than the one you were going for in the first place. This can be done by comparing the priority numbers (one can use an "int" variable for this) for the possible move for all open deck cards and then play the one that has the highest priority.

For more strategies try the following links-

http://www.chessandpoker.com/solitaire_strategy.html

http://www.semicolon.com/Solitaire/Articles/Klondike.html

Well, this is just a drop in the ocean of the possible strategies one can employ to handle this popular card game. Working through this article I discovered the complexities in such a simple and "harmless" looking game as Solitaire. I donít know what complexities other games might possess. Its a tough game to build a game. Believe it !!