about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/downloads/csls-programs/cards
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
committerelioat <elioat@tilde.institute>2023-08-23 07:52:19 -0400
commit562a9a52d599d9a05f871404050968a5fd282640 (patch)
tree7d3305c1252c043bfe246ccc7deff0056aa6b5ab /js/games/nluqo.github.io/~bh/downloads/csls-programs/cards
parent5d012c6c011a9dedf7d0a098e456206244eb5a0f (diff)
downloadtour-562a9a52d599d9a05f871404050968a5fd282640.tar.gz
*
Diffstat (limited to 'js/games/nluqo.github.io/~bh/downloads/csls-programs/cards')
-rw-r--r--js/games/nluqo.github.io/~bh/downloads/csls-programs/cards63
1 files changed, 63 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/downloads/csls-programs/cards b/js/games/nluqo.github.io/~bh/downloads/csls-programs/cards
new file mode 100644
index 0000000..e0df3c6
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/downloads/csls-programs/cards
@@ -0,0 +1,63 @@
+program cards;
+ {Shuffle a deck of cards}
+
+var ranks:array [0..51] of integer;
+    suits:array [0..51] of char;
+    i:integer;
+
+procedure showdeck;
+ {Print the deck arrays}
+
+  begin {showdeck}
+    for i := 0 to 51 do
+      begin
+        if i mod 13 = 0 then writeln;
+        write(ranks[i]:3,suits[i]);
+      end;
+    writeln;
+    writeln
+  end; {showdeck}
+
+procedure deck;
+ {Create the deck in order}
+
+  var i,j:integer;
+      suitnames:packed array [0..3] of char;
+
+  begin {deck}
+    suitnames := 'HSDC';
+    for i := 0 to 12 do
+      for j := 0 to 3 do
+        begin
+          ranks[13*j+i] := i+1;
+          suits[13*j+i] := suitnames[j]
+        end;
+    writeln('The initial deck:');
+    showdeck
+  end; {deck}
+
+procedure shuffle;
+ {Shuffle the deck randomly}
+
+  var rank,i,j:integer;
+      suit:char;
+
+  begin {shuffle}
+    for i := 51 downto 1 do {For each card in the deck}
+      begin
+        j := random(i+1); {Pick a random card before it}
+        rank := ranks[i]; {Interchange ranks}
+        ranks[i] := ranks[j];
+        ranks[j] := rank;
+        suit := suits[i]; {Interchange suits}
+        suits[i] := suits[j];
+        suits[j] := suit
+      end;
+    writeln('The shuffled deck:');
+    showdeck
+  end; {shuffle}
+
+begin {main program}
+  deck;
+  shuffle
+end.