9.5. Dice and Playing Cards

| Chapter 9: Props: Food, Clothing, Money, Toys, Books, Electronics |

| 9.5. Dice and Playing Cards

Most toys are single things, and no harder to create than any other small items, but games often require a multitude of tokens to be combined, and this can be logistically tricky.

The classic example is a pack of playing cards, where the player must individually control 52 items but without fussy commands or verbose text being printed back. Jokers Wild provides a simple "one card at a time" approach; Tilt 1 is more sophisticated, with 52 independently accessible cards; Tilt 2 can further judge the value of a selection of cards - the ranking of a poker hand.

Drawing cards from a shuffled pack is only one source of randomness. Games of chance also involve items drawn from a bag: Wonka's Revenge provides just such a lottery. More often, dice are thrown. A single die is easy enough:

> The die is carried by the player. After dropping the die: say "It lands with [a random number from 1 to 6] uppermost." Understand "roll [something]" as dropping.

Quick, but not very good. Most dice games involve rolling more than one die at a time, to get a more interesting distribution of outcomes: they may also involve special rules applying to doubles, for instance. See Do Pass Go.

See Typography for on-screen notations for chess and card games

264
| Example Jokers Wild A deck of cards which can be shuffled and dealt from. |
WI

306
| Example Tilt 1 A deck of cards with fully implemented individual cards, which can be separately drawn and discarded, and referred to by name. |
WI

> We've simulated a deck of cards before, but only as entries in a table. This time we're going to do it more completely, with card objects that can be drawn and discarded, and referred to by name. The tedious way to do this would be to make 52 objects by hand and laboriously write out their names and understand rules. A more sensible way is to make 52 identical card objects, assign them ranks and suits, and allow Inform to generate and parse their names automatically. So: "Tilt" Section 1 - Cards Suit is a kind of value. The suits are hearts, clubs, diamonds, and spades. Understand "heart" as hearts. Understand "club" as clubs. Understand "diamond" as diamonds. Understand "spade" as spades. [Providing the singular forms means that Inform will also understand >EXAMINE SPADE, >DISCARD CLUB, and so on.] A card is a kind of thing. A card has a suit. A card has a number called rank. Understand the suit property as describing a card. Understand the rank property as describing a card. 52 cards are in the card repository. Now, we're going to describe the higher numbers as face cards, so it helps to write a new "to say" phrase, just as we did in Jokers Wild. (A subsequent version of this example shows how to print card values with red and black symbols representing the different suits; see "Tilt 3".) To say (count - a number) as a card value: choose row count in the Table of Value Names; say "[term entry]". Rule for printing the name of a card (called target): say "[rank of the target as a card value] of [suit of the target]" Table of Value Names
> term | value | topic
> "ace" | "1" | "ace/A/one"
> "deuce" | "2" | "deuce/two"
> "three" | "3" | "three"
> "four" | "4" | "four"
> "five" | "5" | "five"
> "six" | "6" | "six"
> "seven" | "7" | "seven"
> "eight" | "8" | "eight"
> "nine" | "9" | "nine"
> "ten" | "10" | "ten"
> "jack" | "11" | "jack/knave/J"
> "queen" | "12" | "queen/Q"
> "king" | "13" | "king/K"
This is enough already to let inform understand things like "ten clubs", but we want to add a couple of refinements. For one thing, we'd like to accept "of" when it appears in phrases such as "ten of clubs" (but not generically otherwise); for another, we'd like the player to be able to use various names for ranks. To this end, we need to borrow from the Activities chapter and modify the player's command before attempting to understand it: After reading a command: if the player's command includes "of [suit]": while the player's command includes "of": cut the matched text; repeat through the Table of Value Names: while the player's command includes topic entry: replace the matched text with value entry. [This allows Inform to understand "ace", "deuce", "king", etc., as numerical ranks.] It may be a bit confusing that the Table of Value Names has both a topic column and a term column, to all appearances essentially identical. But items in the topic column can be matched against the player's input, whereas items in other kinds of text column can be printed out; the two kinds of text are not treated identically by Inform, so we need to have both. Notice that the topic column contains entries like "jack/knave," which will match either "jack" or "knave" in the player's input. Now to set up the deck at the outset. With some intelligent looping, we avoid having to declare every combination of suit and number individually: When play begins: reconstitute deck. To reconstitute deck: let current suit be hearts; now every card is in the card repository; while a card is in the card repository: repeat with current rank running from 1 to 13: let item be a random card in card repository; now rank of item is current rank; now suit of item is current suit; now item is in the deck of cards; now current suit is the suit after the current suit. And now we need a simple setting and some actions to manipulate the deck with: Section 2 - The Deck and the Discard Pile The Empty Room is a room. "Nothing to see here." The deck of cards is in the Empty Room. It is a closed unopenable container. The description is "A standard poker deck." The discard pile is a closed unopenable container. The description is "Cards in this game are discarded face-down, so the discard pile is not very interesting to see. All you can observe is that it currently contains [if the number of cards which are in the discard pile is less than ten][the number of cards which are in the discard pile in words][otherwise]about [the rounded number of cards which are in the discard pile in words][end if] card[s]." To decide what number is the rounded number of (described set - a description of objects): let N be the number of members of the described set; let R be N divided by 5; let total be R times 5; decide on total. The above phrase rounds a number to the nearest five, so that the player is not autistically able to count a large number of cards in the discard pile at a single glance. This next bit is an optional borrowing from the Activities chapter: we want to prevent Inform printing things like "You can see a discard pile (closed) here.", since we don't want the player to think of the piles as containers, even though Inform thinks of them in those terms. Rule for printing room description details of something: do nothing instead. Finally, we want the player to use "draw" and "discard" to manipulate his hand of cards: Section 3 - Drawing and Discarding Actions Understand the commands "take" and "carry" and "hold" and "get" and "drop" and "throw" and "discard" as something new. Understand "take [text]" or "get [text]" or "drop [text]" as a mistake ("Here, you only draw and discard. Nothing else matters at the moment."). Understand "draw" or "draw card" or "draw a card" as drawing. Drawing is an action applying to nothing. The drawing action has an object called the card drawn. Setting action variables for drawing: now the card drawn is a random card which is in the deck of cards. Check drawing: if the card drawn is nothing, say "The deck is completely depleted." instead. Check drawing: if the number of cards carried by the player is greater than four, say "This is a five-card game; you must discard something before drawing anything further." instead. Carry out drawing: move the card drawn to the player. Report drawing: say "You draw [a card drawn]." Understand "discard [card]" as discarding. Discarding is an action applying to one thing. Check discarding: if the player does not carry the noun, say "You can only discard cards from your own hand." instead. Carry out discarding: now the noun is in the discard pile; if the discard pile is not visible, move the discard pile to the location. Report discarding: say "You toss [the noun] nonchalantly onto the discard pile." Seeding is an action out of world. Understand "seed" as seeding. Carry out seeding: seed the random-number generator with 5681. Test me with "seed / draw / g / g / g / g / i / discard seven of spades / draw / discard six / draw / i / discard hearts / discard six of diamonds card / draw / draw / i / discard spades card / draw / discard king card".

389
| Example Tilt 2 A deck of cards with fully implemented individual cards; when the player has a full poker hand, the inventory listing describes the resulting hand accordingly. |
WI

175
| Example Wonka's Revenge A lottery drum which redistributes the tickets inside whenever the player spins it. |
WI

129
| Example Do Pass Go A pair of dice which can be rolled, and are described with their current total when not carried, and have individual scores when examined. |
WI

Previous | Contents | Next