How to resolve the algorithm Deal cards for FreeCell step by step in the zkl programming language
How to resolve the algorithm Deal cards for FreeCell step by step in the zkl programming language
Table of Contents
Problem Statement
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. (The FreeCell FAQ tells this history.) As the game became popular, Jim Horne disclosed the algorithm, and other implementations of FreeCell began to reproduce the Microsoft deals. These deals are numbered from 1 to 32000. Newer versions from Microsoft have 1 million deals, numbered from 1 to 1000000; some implementations allow numbers outside that range. The algorithm uses this linear congruential generator from Microsoft C:
The algorithm follows: Deals can also be checked against FreeCell solutions to 1000000 games. (Summon a video solution, and it displays the initial deal.) Write a program to take a deal number and deal cards in the same order as this algorithm. The program may display the cards with ASCII, with Unicode, by drawing graphics, or any other way. Related tasks:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Deal cards for FreeCell step by step in the zkl programming language
Source code in the zkl programming language
var suits=T(0x1F0D1,0x1F0C1,0x1F0B1,0x1F0A1); //unicode 🃑,🃁,🂱,🂡
var seed=1; const RMAX32=(1).shiftLeft(31) - 1;
fcn rnd{ (seed=((seed*214013 + 2531011).bitAnd(RMAX32))).shiftRight(16) }
fcn game(n){
seed=n;
deck:=(0).pump(52,List,'wrap(n){ if(n>=44) n+=4; // I want JQK, not JCQ
(suits[n%4] + n/4).toString(8) }).copy(); // int-->UTF-8
[52..1,-1].pump(Void,'wrap(len){ deck.swap(len-1,rnd()%len); });
deck.reverse();
println("Game #",n);
foreach n in ([0..51,8]){ deck[n,8].concat(" ").println(); }
}
game(1);
game(617);
You may also check:How to resolve the algorithm Almost prime step by step in the Processing programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the Fantom programming language
You may also check:How to resolve the algorithm Date manipulation step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Ludic numbers step by step in the Tcl programming language
You may also check:How to resolve the algorithm Mad Libs step by step in the Factor programming language