How to resolve the algorithm Deal cards for FreeCell step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Deal cards for FreeCell step by step in the UNIX Shell 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 UNIX Shell programming language

Source code in the unix programming language

test $# -gt 0 || set -- $((RANDOM % 32000))
for seed; do
	print Game $seed:

	# Shuffle deck.
	deck=({A,{2..9},T,J,Q,K}{C,D,H,S})
	for i in {52..1}; do
		((seed = (214013 * seed + 2531011) & 0x7fffffff))
		((j = (seed >> 16) % i + 1))
		t=$deck[$i]
		deck[$i]=$deck[$j]
		deck[$j]=$t
	done

	# Deal cards.
	print -n ' '
	for i in {52..1}; do
		print -n ' '$deck[$i]
		((i % 8 == 5)) && print -n $'\n '
	done
	print
done


  

You may also check:How to resolve the algorithm Prime triangle step by step in the Go programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Munchausen numbers step by step in the Elixir programming language
You may also check:How to resolve the algorithm SOAP step by step in the Python programming language
You may also check:How to resolve the algorithm Substring step by step in the Euphoria programming language