Inform 7 Home Page / Documentation
§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
Start of Chapter 9: Props: Food, Clothing, Money, Toys, Books, Electronics | |
Back to §9.4. Money | |
Onward to §9.6. Reading Matter |
ExampleDo Pass Go |
Go is a room. "A giant square area, where you and your other pewter ornament friends gather before setting out to purchase London."
The pair of dice has a number called first die. The pair of dice has a number called second die. The first die of the pair is 6. The second die of the pair is 6. Rule for printing the name of the pair of dice while taking inventory: say "pair of dice".
Rule for printing the name of the pair of dice: say "pair of dice showing [first die of the pair plus second die of the pair]".
To say detailed state of the dice:
if the first die of the pair is the second die of the pair, say "double [first die of the pair]";
otherwise say "[first die of the pair] and [second die of the pair]".
The description of the pair of dice is "The pair of dice are [if the dice are carried]itching to be rolled[otherwise]showing [detailed state of the dice][end if]."
Rolling is an action applying to one carried thing. Understand "roll [something preferably held]" as rolling.
Check rolling when the noun is not the pair of dice: say "Not something you can roll." instead.
Carry out rolling:
now the pair of dice is in the holder of the actor;
now the first die of the pair of dice is a random number from 1 to 6;
now the second die of the pair of dice is a random number from 1 to 6.
Report rolling:
say "You roll [detailed state of the dice]."
Test me with "i / roll dice / look / x dice / get dice / x dice / roll dice / roll dice / roll dice / roll dice / roll dice / roll dice / roll dice".
Because we remember the states of the individual dice, not just a total, we can make use of the combination rolled.
The doubles count is a number that varies.
After rolling:
if the first die of the pair is the second die of the pair, increment the doubles count;
otherwise now the doubles count is 0;
continue the action.
Jail is a room. "This is Jail, and not the Just Visiting periphery, either."
Every turn when the doubles count is 3:
say "The blue-uniformed policemen blows his whistle and beckons you sternly...";
now the player carries the pair of dice;
now the player is in Jail;
now the doubles count is 0.
Every turn when the doubles count is 1 and the player is in Jail:
say "The warden gruffly releases you.";
now the player carries the pair of dice;
now the player is in Go.
ExampleWonka's Revenge |
The Caribou Lodge is a room. "Hundreds of expectant faces are turned your way from every table." A lottery drum is in the Lodge. "Before you is the lottery drum[if we have spun the drum], ready to disgorge a ticket[otherwise], waiting to be spun[end if]." In the drum are a red ticket, an orange ticket, a yellow ticket, a green ticket, a blue ticket, a purple ticket, and a ticket of pure gold. The drum is closed and openable.
Check spinning: if the noun is an open container which contains something, say "[The list of things in the noun] would fly out." instead.
Carry out spinning a container:
shuffle the contents of the noun.
Report spinning:
if the noun contains something, say "You rattle [if the noun is transparent][the list of things in the noun][otherwise]the stuff[end if] in [the noun].";
otherwise say "Nothing results of your shaking [the noun]."
Inform keeps track of the order in which things have been put into a container. If we want to change that order without the player's intervention, we can move the things ourselves.
To shuffle the contents of (basket - a container):
let moves be the number of things in the basket;
repeat with counter running from 1 to moves:
move a random thing in the basket to the basket.
After opening the drum when we have spun the drum for the first time:
if something (called the pick) is in the drum:
try searching the drum;
say "[The pick] it is, then.";
silently try taking the pick;
if the pick is the ticket of pure gold, end the story finally;
otherwise end the story saying "Oh well, better luck next time."
Test me with "open drum / look in drum / close drum / spin drum / open drum".
ExampleJokers Wild |
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:
Suit is a kind of value. The suits are hearts, clubs, diamonds, and spades.
suit |
value |
diamonds |
1 |
diamonds |
2 |
diamonds |
3 |
diamonds |
4 |
diamonds |
5 |
diamonds |
6 |
diamonds |
7 |
diamonds |
8 |
diamonds |
9 |
diamonds |
10 |
diamonds |
11 |
diamonds |
12 |
diamonds |
13 |
spades |
1 |
spades |
2 |
spades |
3 |
spades |
4 |
spades |
5 |
spades |
6 |
spades |
7 |
spades |
8 |
spades |
9 |
spades |
10 |
spades |
11 |
spades |
12 |
spades |
13 |
hearts |
1 |
hearts |
2 |
hearts |
3 |
hearts |
4 |
hearts |
5 |
hearts |
6 |
hearts |
7 |
hearts |
8 |
hearts |
9 |
hearts |
10 |
hearts |
11 |
hearts |
12 |
hearts |
13 |
clubs |
1 |
clubs |
2 |
clubs |
3 |
clubs |
4 |
clubs |
5 |
clubs |
6 |
clubs |
7 |
clubs |
8 |
clubs |
9 |
clubs |
10 |
clubs |
11 |
clubs |
12 |
clubs |
13 |
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]".
value |
term |
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.".
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.
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.
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".
ExampleTilt 1 |
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:
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.
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]"
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:
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:
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, because it seems unrealistic for the player to be 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:
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.
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".
ExampleTilt 2 |
In our previous implementations of playing cards, we've gotten as far as creating decks of individual cards that the player can draw and discard. But in a poker game, one doesn't just have a collection of cards: one has a hand of a specific kind.
Here we take on the job of writing an inventory listing for a poker hand that will reflect the real value of what the player has drawn. To do this, we create a rulebook to sort and assess the cards in the player's hand; its possible return values are limited to the kinds of poker hands that exist, from "high card" to "royal flush".
The first three sections, creating the deck of cards and the means to parse their names, are identical to those we've already seen in Tilt 1; new material begins at section 4.
For the purposes of demonstration, we're simulating something akin to five-card draw without wilds; stud or hold-em variations would add some other complexities.
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.
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.
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]"
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" |
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.
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.
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.
Rule for printing room description details of something: do nothing instead.
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.
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."
New material begins here. We want to start by grouping cards together, but identifying poker hands only if the player holds a full five cards.
Before listing contents while taking inventory: group cards together.
Before grouping together cards:
if the number of cards carried by the player is 5:
say "[run paragraph on]";
follow the hand-ranking rules;
if the rule succeeded, say "[the outcome of the rulebook]";
otherwise say "some random cards";
if the outcome of the rulebook is pair outcome, say " of [rank of the first thing held by the player as a card value]s";
otherwise:
say "[number of cards carried by the player in words] assorted cards";
say " (".
To say list hand:
let chosen card be the first thing held by the player;
while chosen card is a card:
say "[chosen card]";
now chosen card is the next thing held after chosen card;
if chosen card is a card, say ", ".
The ranking of poker hands traditionally depends on three features: 1) whether all the cards are of the same suit (flush); 2) whether the cards constitute a numerical run of ranks (straight); and 3) how many cards or sets of cards are of matching rank (pairs, three of a kind, and four of a kind). Here we will start by assessing our hand to determine these qualities:
The hand-ranking rules is a rulebook. The hand-ranking rules have outcomes royal flush, straight flush, four of a kind, full house, flush, straight, three of a kind, two pairs, pair, high card.
The hand-ranking rulebook has a truth state called the flushness.
The hand-ranking rulebook has a truth state called the straightness.
The hand-ranking rulebook has a number called the pair count.
The hand-ranking rulebook has a number called the triple count.
The hand-ranking rulebook has a number called the quadruple count.
For convenience in identifying hand features, and for elegance when we print the hand-listing, we start by sorting the cards in the player's hand so that the high-ranked cards are listed first. It is rare that we want to concern ourselves with this, but as we saw in the section on "Looking at containment by hand" in the chapter on Change, Inform keeps an ordered list of the items inside any given container; so it does order the objects in the player's hand, and the ordering depends on which things were added to the hand most recently. By moving something to the player's hand again (even if it was already there), we change this ordering, and wind up with a sorted hand.
A card can be sorted or unsorted. A card is usually unsorted.
Definition: a card is high if its rank is 11 or more.
Definition: a card is low if its rank is 4 or less.
A hand-ranking rule (this is the initial sort rule):
now every card is unsorted;
while the player carries an unsorted card:
let item be the lowest unsorted card held by the player;
move item to the player;
now the item is sorted;
if sort-debugging is true, say "-- after initial sort: [list hand]".
This last printing instruction is there for diagnostic purposes: later we'll add a testing command to turn debugging on and off; when it's on, the game will print out its card list at various stages in sorting, to help us trouble-shoot any problems. In normal play, however, this will be off.
Next up, a check to see whether the player has a flush:
A hand-ranking rule (this is the finding flushness rule):
let called suit be the suit of a random card carried by the player;
if every card carried by the player is called suit, now flushness is true.
Now we check for straights; this is slightly complicated by the fact that an ace can be either the bottom of a low straight (lower than 2) or the top of a high straight (higher than king), so we explicitly check both possibilities.
A hand-ranking rule (this is the finding straightness rule):
now straightness is true;
let N be the rank of the highest card which is carried by the player;
repeat with current rank running from N - 4 to N:
now the test rank is the current rank;
unless the player carries a matching card:
if the current rank is N - 4 and the current rank is 9 and the player carries an ace card, do nothing; [this covers the case where an ace could be the top card of the sequence]
otherwise now straightness is false.
And finally, we need to identify any groups of cards of the same rank. We want to know how many groups there are and how large each group is (though in practice there can only be one group of three or four in a standard-sized poker hand). We also want to mark any grouped cards so that we can move them to the front of the player's hand when we take inventory.
Test rank is a number that varies. Definition: a card is matching if its rank is the test rank.
This definition is a convenience so that we don't have to write so many explicit loops in the following rule:
A hand-ranking rule (this is the counting multiples rule):
now every card is uncombined;
repeat with current rank running from 1 to 13:
now test rank is current rank;
let N be the number of matching cards held by the player;
if N is 4:
increment the quadruple count;
now every matching card held by the player is quadrupled;
if N is 3:
increment the triple count;
now every matching card held by the player is tripled;
if N is 2:
increment the pair count;
now every matching card held by the player is paired.
Next we tweak our sorting to reflect the make-up of the hand. There are two reasons why this might differ from the straight highest-to-lowest sort we did earlier:
1) we want to list aces as high unless they are serving as the bottom of a low straight, in which case they should appear last;
2) we want combinations to appear at the front of the list, sorted from highest value to lowest value: larger combinations first, then smaller combinations, and combinations of equal size sorted by rank.
A hand-ranking rule (this is the move aces up unless there's a low straight rule):
unless the straightness is true and the lowest card carried by the player is an ace card and the rank of the highest card carried by the player is 5,
now every ace card which is carried by the player is carried by the player;
if sort-debugging is true, say "-- after ace movement rule: [list hand]".
A hand-ranking rule (this is the move pairs forward rule):
while the player carries a paired card:
let selection be the lowest paired card which is carried by the player;
move the selection to the player;
now the selection is uncombined;
if sort-debugging is true, say "-- after pairs movement: [list hand]".
A hand-ranking rule (this is the raise ace pairs rule):
if the player carries exactly two ace cards:
repeat with item running through ace cards which are carried by the player:
move item to the player;
if sort-debugging is true, say "-- after paired-ace movement: [list hand]".
A hand-ranking rule (this is the move multiples forward rule):
while the player carries a tripled card:
let selection be the lowest tripled card which is carried by the player;
move the selection to the player;
now the selection is uncombined;
while the player carries a quadrupled card:
let selection be the lowest quadrupled card which is carried by the player;
move the selection to the player;
now the selection is uncombined;
if sort-debugging is true, say "-- after multiples movement rule: [list hand]".
Definition: a card is ace if its rank is 1.
Definition: a card is king if its rank is 13.
Now, having determined the salient qualities of our hand, we run through rules in order from the highest kind of poker combination to the lowest. Because of the order of the source, Inform will choose whichever combination applies first.
A hand-ranking rule (this is the royal-flush rule):
if flushness is true and straightness is true and the highest card carried by the player is king and the lowest card carried by the player is ace, royal flush.
A hand-ranking rule (this is the straight-flushes rule):
if flushness is true and straightness is true, straight flush.
A hand-ranking rule (this is the four-of-a-kind rule):
if the quadruple count is 1, four of a kind.
A hand-ranking rule (this is the full-house rule):
if the pair count is 1 and the triple count is 1, full house.
A hand-ranking rule (this is the flushes rule):
if flushness is true, flush.
A hand-ranking rule (this is the straights rule):
if straightness is true, straight.
A hand-ranking rule (this is the three-of-a-kind rule):
if triple count is 1, three of a kind.
A hand-ranking rule (this is the two-pair rule):
if the pair count is 2, two pairs.
A hand-ranking rule (this is the pair rule):
if the pair count is 1, pair.
And finally, we need to define our debugging variable here, even though we won't give the player the ability to turn it on and off except in the special testing section.
For many examples, a test-me script is enough to prove that the example does what it ought. This example, though, is a bit more complicated, and hard to test randomly. The remainder of the source here shows how we might write a test to verify the desired behavior of our rulebook. Those who are only interested in the rulebook itself can stop reading at this point.
For the sake of testing our rules, we provide an apparatus that will load the player's hand up with sample hands of each kind, then show the result to make sure that the hand is being correctly identified.
Understand "debug sorting" as debugging hand sorting. Debugging hand sorting is an action out of world.
Carry out debugging hand sorting:
if sort-debugging is false, now sort-debugging is true;
otherwise now sort-debugging is false.
Report debugging hand sorting:
say "Sort debugging is now [if sort-debugging is true]on[otherwise]off[end if]."
Test me with "draw / g / g / g / g / force hand / g / g / g / g / g / g / g / g / g / g / g / g".
The somewhat rough-and-ready principle of this table is that we will overwrite the cards in the player's hand by resetting their ranks and suits; every five rows of the table represent a new poker hand for the game to attempt to sort and identify. These include one example of each of the major kinds of poker hand, plus a couple of variations involving aces which test the special sorting rules.
set suit |
set rank |
|
spades |
1 |
[royal flush] |
spades |
13 |
|
spades |
12 |
|
spades |
11 |
|
spades |
10 |
|
clubs |
12 |
[straight flush] |
clubs |
11 |
|
clubs |
10 |
|
clubs |
9 |
|
clubs |
8 |
|
diamonds |
8 |
[four of a kind] |
hearts |
8 |
|
spades |
8 |
|
clubs |
8 |
|
clubs |
3 |
|
clubs |
1 |
[full house] |
spades |
1 |
|
hearts |
10 |
|
spades |
10 |
|
clubs |
10 |
|
hearts |
2 |
[flush] |
hearts |
5 |
|
hearts |
7 |
|
hearts |
11 |
|
hearts |
12 |
|
hearts |
1 |
[straight] |
spades |
13 |
|
diamonds |
12 |
|
clubs |
11 |
|
hearts |
10 |
|
hearts |
2 |
[three of a kind] |
spades |
2 |
|
clubs |
2 |
|
clubs |
4 |
|
spades |
3 |
|
diamonds |
6 |
[two pairs] |
spades |
6 |
|
clubs |
7 |
|
diamonds |
7 |
|
hearts |
9 |
|
diamonds |
6 |
[two pairs, ace high] |
spades |
6 |
|
clubs |
1 |
|
diamonds |
7 |
|
hearts |
1 |
|
hearts |
12 |
[pair] |
spades |
12 |
|
diamonds |
10 |
|
spades |
7 |
|
clubs |
4 |
|
diamonds |
13 |
[high] |
hearts |
11 |
|
spades |
9 |
|
clubs |
7 |
|
diamonds |
5 |
|
hearts |
1 |
[tricky sorting: low straight] |
diamonds |
2 |
|
spades |
3 |
|
diamonds |
4 |
|
diamonds |
5 |
Understand "force hand" as forcing a hand. Forcing a hand is an action out of world.
Carry out forcing a hand:
repeat with item running through cards which are carried by the player:
increment current marker;
if current marker is greater than the number of filled rows in the Table of Testing Hands, now current marker is 1;
choose row current marker in the Table of Testing Hands;
now the suit of item is the set suit entry;
now the rank of item is the set rank entry.