This entry was originally stored in my personal blog engine, but has been imported into WordPress.
I came up with a solution to the Poker Solitaire question, a quick method to:
- Ensure that all dealt hands will win.
- Use an algorithm that will do this within a reasonable time (which, for me, means almost instantly).
- Still allow random deals from a standard deck of cards (that is, no creating a list of pre-generated games).
The hint came from my proof on how it was possible to lose a Poker Solitaire hand. While it is extremely time-consuming to iterate through possible deals, it is extremely simple and quick to determine, in a given deal, how many potential flushes, full houses, and straights the deal has.
In the end, I settled on the following rules for each deal. If a random deal doesn’t meet the criteria, the program automatically deals a new hand. Each deal must:
- Have a minimum of 3 potential flushes.
- Have a minimum of 3 potential full houses
- Contain at least 1 of each possible value (which guarantees at least 2 potential straights)
NOTE: On my first try, I also allowed deals that were missing at most 1 of the values in the deck, but was still able to produce a losing game. Given that, this should be close to the smallest set of rules necessary.
I then created the following proof, again by trying to produce the weakest possible hand using the existing rules. The key to dealing a bad hand within the rules is to maximize the number of tradeoffs a player needs to make (e.g., pulling a card from an existing flush to complete a straight). Here’s how I dealt:
- Hold to 3 flushes in the following manner. The fewer cards of the same suit, the harder it is to keep a flush, since shifting cards can break it. In my example, I used 7 cards each of spades, hearts, and clubs, and then 4 diamonds.
- Deal only one 6 and one Jack, using one of the flush suits. This uses all possible values, but with a bottleneck that limits possible straights to 2. In addition, by using one of the flush suits (in my example, spades), you’re increasing the chance that either the flush or the straight can be broken up.
- Hold to 3 triples in the following manner. Deal 3 each of the values 8, 9, and 10, using spades, hearts, and clubs. By using the flush suits, you increase the necessity of breaking a flush or triple in favor of one or the other. By using consecutive numbers, you create the same tradeoff between triples and straights.
- Deal one card each of the values 2-5 from the non-flush suit. In my example, the 2, 3, 4, and 5 of diamonds. This isolates these values as much as possible from the rest of the cards, and makes them harder to use.
- Proceed with the rest of the deal like this. Deal 2 each of 7s, queens, kings, and aces, staggered along the 3 flush suits. This keeps each of these values down to 2 each. Since we’re already minimizing the straights, it is okay to deal them like this.
Following these rules, you can deal 23 of the 25 cards. After this, the least useful cards would be one of the values 2, 3, or 4 from the flush suits . This creates another value bottleneck (at 5), and all it does is give the hand 2 more pairs. I chose the 2 of hearts and 3 of clubs.
Despite all these limitations, you can still win this hand with a combination of straights and flushes (the easiest rows to create):
So finally, you’re guaranteed to win! No more chances of endlessly shifting around cards.
This being proven, I’m just about done with Poker Solitaire. This was supposed to be a simple app game taking several hours of coding. It ended up feeling like a work project and a university midterm rolled into one. I’m off to post this on Newgrounds. After some feedback, and perhaps updating the graphics a bit, I’m going to throw it into the WebView of an Android app, and then into my outbox.