Jokers Wild

Example 275
★★

A deck of cards which can be shuffled and dealt from.

Suppose we want a deck of cards which the player can shuffle and draw from. Our first (rather tedious) task is merely to set up the deck as a table:

"Jokers Wild"
Suit is a kind of value. The suits are hearts, clubs, diamonds, and spades.
Table of Cards
suitvalue
diamonds1
diamonds2
diamonds3
diamonds4
diamonds5
diamonds6
diamonds7
diamonds8
diamonds9
diamonds10
diamonds11
diamonds12
diamonds13
spades1
spades2
spades3
spades4
spades5
spades6
spades7
spades8
spades9
spades10
spades11
spades12
spades13
hearts1
hearts2
hearts3
hearts4
hearts5
hearts6
hearts7
hearts8
hearts9
hearts10
hearts11
hearts12
hearts13
clubs1
clubs2
clubs3
clubs4
clubs5
clubs6
clubs7
clubs8
clubs9
clubs10
clubs11
clubs12
clubs13

We're going to describe the higher numbers as face cards, so it helps to write a new "to say" phrase.

To say (count - a number) as a card value:
   choose row with a value of count in the Table of Value Names;
   say "[term entry]".
Table of Value Names
valueterm
1"ace"
2"deuce"
3"three"
4"four"
5"five"
6"six"
7"seven"
8"eight"
9"nine"
10"ten"
11"jack"
12"queen"
13"king"

Now we get the shuffling of the deck from "sort in random order", so:

Understand "shuffle" as shuffling. Shuffling is an action applying to nothing.
Carry out shuffling:
   sort the Table of Cards in random order;
   say "You expertly rearrange the cards.".
When play begins:
   sort the Table of Cards in random order.

This will continue to work properly even as the deck is partially depleted. Speaking of which, suppose we want the player to be able to toss the cards one-by-one into a hat. They are going to need to be removed from the deck, so:

Understand "toss" or "toss a card" or "toss card" as tossing.
Tossing is an action applying to nothing.
Check tossing:
   if the number of filled rows in the Table of Cards is 0, say "The deck is empty." instead.
Carry out tossing:
   repeat through the Table of Cards:
      let new value be value entry;
      let new suit be suit entry;
      say "You throw the [value entry as a card value] of [suit entry] at the top hat, and [if a random chance of 1 in 3 succeeds]hit[otherwise]miss[end if].";
      blank out the whole row;
      rule succeeds.

If we wanted to simulate a slightly more stimulating game, we could instead have a second table to represent the player's hand of cards and record each card drawn. That would get long for the purposes of example, however, so instead we will just admit that the player's life is an empty husk of existence:

The Empty Room is a room. "It has come to this: sitting on the bare floor of Lulu's apartment with nothing to amuse you but a deck of cards and the top hat from last year's act. You reckon [the number of filled rows in the Table of Cards in words] cardtosses are all that stand between you and the utter pointlessness of existence.
Once again you curse Lulu for running off with that joker."
The player is carrying the deck of cards. The top hat is an open container in the Empty Room. It is scenery.
Test me with "toss / again / again / again / again / again / again / again".
Test me with "toss / again / again / again / again / again / again / again".
Empty Room
It has come to this: sitting on the bare floor of Lulu's apartment with nothing to amuse you but a deck of cards and the top hat from last year's act. You reckon fifty-two cardtosses are all that stand between you and the utter pointlessness of existence.

Once again you curse Lulu for running off with that joker.

>(Testing.)

>[1] toss
You throw the deuce of clubs at the top hat, and hit.

>[2] again
You throw the seven of hearts at the top hat, and miss.

>[3] again
You throw the deuce of spades at the top hat, and miss.

>[4] again
You throw the eight of hearts at the top hat, and miss.

>[5] again
You throw the three of clubs at the top hat, and hit.

>[6] again
You throw the five of clubs at the top hat, and hit.

>[7] again
You throw the nine of clubs at the top hat, and hit.

>[8] again
You throw the three of spades at the top hat, and hit.