"Autumn Leaves" by "Daniel M. Stelzer (based on the game by Toby Ord)" Release along with the source text, the "Quixe" interpreter, and a "StatCounter" website. The story headline is "An Interactive Game of Solitaire". Include Typographical Conveniences by Daniel Stelzer. [This is an implementation of the solitaire card game "Autumn Leaves" by Toby Ord, built mostly as an example of using playing cards and playing card mechanics in Inform. It requires some Unicode support to visualize the card stacks properly (the line-drawing codepoints in particular).] Section A - Cards A suit is a kind of value. The suits are hearts, diamonds, clubs, and spades. Understand "heart" as hearts. Understand "diamond" as diamonds. Understand "club" as clubs. Understand "spade" as spades. A card is a kind of object. A card has a number called the face value. A card has a suit. Rule for printing the name of a card: say "[face value as card value] of [suit]". To say (N - number) as a/-- card value: if N is: -- 1: say "ace"; -- 2: say "deuce"; -- 11: say "jack"; -- 12: say "queen"; -- 13: say "king"; -- otherwise: say N. Understand "ace" or "a" as a card when the face value of the item described is 1 and the item described is face-up. Understand "deuce" as a card when the face value of the item described is 2 and the item described is face-up. Understand "jack" or "knave" or "prince" or "j" as a card when the face value of the item described is 11 and the item described is face-up. Understand "queen" or "q" as a card when the face value of the item described is 12 and the item described is face-up. Understand "king" or "k" as a card when the face value of the item described is 13 and the item described is face-up. Understand the face value property as describing a card when the item described is face-up. Understand the suit property as describing a card when the item described is face-up. Understand "of" as a card. Understand "card" as a card. Definition: a card is unallocated if its face value is 0. A card can be played or unplayed. A card is usually unplayed. A card can be face-up or face-down. A card is usually face-down. To say abbreviation of (N - number): if N is: -- 1: say "A"; -- 10: say "Ю"; [Cyrillic yu looks a lot like "10" in the monospaced font] -- 11: say "J"; -- 12: say "Q"; -- 13: say "K"; -- otherwise: say N. To say abbreviation of (S - suit): if S is: -- hearts: say "♥"; -- diamonds: say "♦"; -- clubs: say "♣"; -- spades: say "♠". To say abbreviation of (C - card): say "[abbreviation of the face value of C][abbreviation of the suit of C]". To say inverse abbreviation of (C - card): say "[abbreviation of the suit of C][abbreviation of the face value of C]". Definition: a card (called the item) is heart-suited if the suit of the item is hearts. Definition: a card (called the item) is diamond-suited if the suit of the item is diamonds. Definition: a card (called the item) is club-suited if the suit of the item is clubs. Definition: a card (called the item) is spade-suited if the suit of the item is spades. There are 52 cards. When play begins: seed the random-number generator with 1; [With seed 1 the generator always returns zero, so this numbers all the cards in order. Not strictly necessary but nice for organization.] repeat with the color running through suits: repeat with the new value running from 1 to 13: let the item be a random unallocated card; now the suit of the item is the color; now the face value of the item is the new value; seed the random-number generator with 0. Section B - Piles There is a room called the Gaming Room. "You are seated before a felt table, on which a robotic dealer stands ready. Say DEAL to begin." The felt table is scenery in the Gaming Room. The robotic dealer is scenery in the Gaming Room. A pile is a kind of thing. A pile has a list of cards called the contents. The first pile, the second pile, the third pile, the fourth pile, the fifth pile, and the sixth pile are piles in the Gaming Room. A pile is usually scenery. To deal the cards: now every card is unplayed; now every card is face-down; repeat with the item running through piles: now the contents of the item are {}; add three cards to the item; add one card to the first pile; add one card to the second pile; add one card to the fifth pile; add one card to the sixth pile; repeat with the item running through piles: repeat with the page running through the contents of the item: now the page is face-down; now entry 1 in the contents of the item is face-up. To draw more cards: if the number of unplayed cards is 0: say "There are no more cards!"; stop; repeat with the item running through piles: add one card to the item. To add (N - number) card/cards to (item - a pile): repeat with na running from 1 to N: let the page be a random unplayed card; now the page is played; now the page is face-up; add the page at entry 1 in the contents of the item. To decide what list of text is the card description of (stack - a pile): if the contents of the stack are empty, decide on {}; let L be the contents of the stack; reverse L; let C be nothing; let Z be a list of text; repeat with the item running through L: if the item is entry 1 in L: add "╔══════╗" to Z; otherwise: add "╠══════╣" to Z; if the item is face-up: add "║[abbreviation of the item] ║" to Z; otherwise: add "║▒▒▒▒▒▒║" to Z; let C be the item; repeat with na running from 1 to 3: add "║ ║" to Z; add "║ [inverse abbreviation of C]║" to Z; add "╚══════╝" to Z; decide on Z. To show all the piles: let Z be a list of lists of text; repeat with the stack running through piles: add the card description of the stack to Z; let the max be zero; repeat with Y running through Z: let N be the number of entries in Y; if N is greater than the max, now the max is N; say fixed letter spacing; repeat with W running from 1 to the max: repeat with X running through Z: if W is greater than the number of entries in X: say " "; otherwise: say entry W in X; say line break; say variable letter spacing. Definition: a pile (called the stack) is empty if the contents of the stack are empty. Understand "empty" as a pile when the item described is empty. Instead of examining a pile: let Z be the card description of the noun; let N be the number of entries in Z; say fixed letter spacing; repeat with X running from 1 to N: [For some reason I can't repeat through Z. If I do, it prints blanks.] say entry X in Z; say line break; say variable letter spacing. To move the top (N - number) card/cards from (donor - pile) to (recipient - pile): let L be a list of objects; repeat with na running from 1 to N: add entry 1 of the contents of the donor to L; remove entry 1 from the contents of the donor; if the contents of the donor are not empty and entry 1 in the contents of the donor is face-down: now entry 1 in the contents of the donor is face-up; reverse L; repeat with the item running through L: add the item at entry 1 in the contents of the recipient. To decide what object is the holder of (item - a card): repeat with the stack running through piles: if the item is listed in the contents of the stack, decide on the stack; decide on nothing. To decide what list of objects is the cards on top of (item - a card): let the stack be the holder of the item; if the stack is nothing, decide on {}; let L be a list of cards; repeat with the page running through the contents of the stack: if the page is the item, break; add the page to L; decide on L; Section C - Actions To decide whether the player has won: if there is a face-down card, no; if there is an unplayed card, no; let N be zero; repeat with the stack running through piles: if the stack is empty: increment N; next; let the color be the suit of entry 1 in the contents of the stack; repeat with the item running through the contents of the stack: if the suit of the item is not the color, no; if N is two, yes. [There must be two empty stacks, no face-down cards, and only one suit per pile.] Every turn: if the player has won, end the story finally saying "You have won"; show all the piles. Moving it to is an action applying to one visible thing and one thing. Understand "move [any card] to [a pile]" as moving it to. The moving it to action has a number called the number of cards moved. Check moving a card to a pile: if the noun is face-down: say "You can't see [the noun] at the moment." instead; let L be the cards on top of the noun; if L is not empty: let N be the number of entries in L; let the old card be the noun; reverse L; repeat with X running from 1 to N: let the new card be entry X in L; let the difference be the face value of the old card minus the face value of the new card; unless the difference is 1 and the suit of the old card is the suit of the new card: say "You can only move a stack of cards when they form a descending run." instead; now the old card is the new card; unless the contents of the second noun are empty: unless the suit of the noun is the suit of entry 1 in the contents of the second noun: say "You can only move a card onto a card of the same suit." instead; if the face value of the noun is greater than the face value of entry 1 in the contents of the second noun: say "You can only move a card onto a card of lesser value." instead; let N be the number of entries in L; increment N; now the number of cards moved is N. Carry out moving a card to a pile: let the stack be the holder of the noun; move the top (number of cards moved) cards from the stack to the second noun. Indirectly moving it to is an action applying to two visible things. Understand "move [any card] to [any card]" as indirectly moving it to. Check indirectly moving a card to a card: if the second noun is face-down, say "You can't see [the second noun] at the moment." instead. Carry out indirectly moving a card to a card: try moving the noun to the holder of the second noun instead. Does the player mean indirectly moving a heart-suited card to a heart-suited card: it is very likely. Does the player mean indirectly moving a diamond-suited card to a diamond-suited card: it is very likely. Does the player mean indirectly moving a club-suited card to a club-suited card: it is very likely. Does the player mean indirectly moving a spade-suited card to a spade-suited card: it is very likely. Seeding the RNG with is an action out of world applying to a number. Understand "seed [number]" as seeding the RNG with. Carry out seeding the RNG with a number: seed the random-number generator with the number understood. Report seeding the RNG with a number: say "Random seed set." Dealing is an action applying to nothing. Understand "deal" as dealing. Check dealing when there is a played card: say "A game is in progress. Are you sure you want to deal again? "; unless the player consents, stop the action. Carry out dealing: deal the cards. Drawing is an action applying to nothing. Understand "draw" as drawing. Check drawing: if the number of unplayed cards is zero: say "There are no cards left." instead. Carry out drawing: repeat with the stack running through piles: add 1 card to the stack.