Shuffling cards for Solitaire?

Started by
12 comments, last by iMalc 18 years, 4 months ago
Thanks for the replies guys! Good stuff.
Advertisement
I think that starting with a finished game brings the same problems because sometimes you won't be able to get the cards to the starting point which is the same as a game you cannot win. You'd have to explore the possible ways to finnally get a playable game. So it's the same as playing the game to find those you cannot win plus you'd have to do all the mechanics to be able to play backward. To create the deck you'd have to randomly choose what to do and finally try to get to a "new game" state.

I think that you won't see a big difference in time and both should be quick to get results. So trying to solve the game feels like the easiest way to do this... as I see it. And occasional gamers either even if it takes 1-2 seconds longer to shuffle a deck

The easy way to solve the game would be the brute force, to try all the different possibilities until you can win or run out of possibilities. (Like in a maze... Explore and when you can't continue, go back and try another path...) If you run out of possibilities the game can't be won so you shuffle and try again until you find a match. More optimal ways would be to define some conditions where you know the game cannot be won and test them as you are goin through the game. Testing for conditions like : if you need that ace of spades to complete the game but you won't be able to move the 5 (of spades) that blocks you because all red 6 are blocked under it too.


JFF
Quote:Original post by jff_f
I think that starting with a finished game brings the same problems because sometimes you won't be able to get the cards to the starting point which is the same as a game you cannot win. You'd have to explore the possible ways to finnally get a playable game. So it's the same as playing the game to find those you cannot win plus you'd have to do all the mechanics to be able to play backward. To create the deck you'd have to randomly choose what to do and finally try to get to a "new game" state.

This was my initial thought as well. The other consideration is that the action space would be huge...going forward, you typically only have two or three possible choices, at any given time. Going backwards, the same is not true. This raises two questions: how do you enumerate the possible moves, and how do you chose among them in such a way that you aren't biased towards certain types of moves? Maybe these aren't such real considerations, I haven't put much thought into it. But it definately seems less straightforward than it appears on the surface.

However...
Quote:Original post by jff_f
And occasional gamers either even if it takes 1-2 seconds longer to shuffle a deck

That's a mighty long time for shuffling. If a brute force method took that long, I would start looking into more elegant solutions.

CM
One of the most time consuming parts of solving a game, regardless of whether you do it forwards or backwards, is to ensure that you never go backwards. By that I mean, not ending up moving a card fomr one pile to another and back again repeatedly, under the mistaken impression that it is still working towards a solvable outcome, when in fact it is not.
This entails making sure that of all the possible moves you consider at each time, discount those which have already occurred in getting you to that point. This duplicate removal will likely be your bottleneck, especially if you attempt to work backwards.

Personally, I'd rather write a FreeCell solver, although there are only a couple of unsolveable variants of those.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement