Deal cards for FreeCell

Revision as of 23:01, 18 September 2011 by rosettacode>Kernigh (Incomplete task.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Free Cell is the solitaire card game that Paul Alfille introduced to the PLATO system in 1978. Jim Horne, at Microsoft, changed the name to FreeCell and reimplemented the game for DOS, then Windows. This version introduced 32000 numbered deals. As the game became popular, Jim Horne disclosed the algorithm, and other implementations of FreeCell began to reproduce the Microsoft deals.

Deal cards for FreeCell is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The algorithm uses this linear congruential generator from Microsoft C:

  • is in range 0 to 32767.
  • Rosetta Code has another task, linear congruential generator, with code for this RNG in several languages.

The algorithm follows:

  1. Seed the RNG with a number from 1 to 1000000. (Some implementations allow numbers outside of this range.)
  2. Put all 52 cards in order: Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, 2 of Diamonds, and so on through the ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King.
  3. (Insert algorithm here.)

Deals can be checked against FreeCell solutions to 1000000 games. (Summon a video solution, and it displays the deal.)

Freecell FAQ