We might want to allow every television to be tuned to a channel (a number property) which the player could refer to, so that
WATCH CHANNEL 13
TURN OFF CHANNEL 4
would be directed to the appropriate television object, if any television is turned on and tuned to the correct station. We might now write:
"Channel"
A television is a kind of device. A television has a number called the channel. Understand the channel property as referring to a television. Understand "channel" as a television.
The Office is a room. The widescreen TV is a television in the Office. The fifties TV is a television in the Office.
Changing the channel of it to is an action applying to one thing and one number.
Understand "tune [something] to [number]" or "change channel of [something] to [number]" as changing the channel of it to.
Check changing the channel of something to:
if the noun is not a television, say "[The noun] cannot be tuned to a channel." instead.
Carry out changing the channel of something to:
now the channel of the noun is the number understood.
Report changing the channel of something to:
say "You tune [the noun] to channel [number understood]."
Instead of examining a television:
if the noun is switched off, say "[The noun] is currently turned off." instead;
let the chosen channel be the channel of the noun;
if the chosen channel is a current channel listed in the Table of Television Channels:
choose row with current channel of the chosen channel in the Table of Television Channels;
say "[output entry][paragraph break]";
otherwise:
say "Snow fills the screen of [the noun]."
Table of Television Channels
current channel
|
output
|
0
|
"The screen of [the noun] is completely black."
|
4
|
"A gloomy female news anchor describes the latest car bomb in Baghdad: 104 dead today, and no sign of change."
|
5
|
"A couple of contestants in spangled scarlet outfits are performing an energetic paso doble."
|
13
|
"On-screen, Ichiro is up to bat with one man on second and no outs."
|
Test me with "change channel of fifties tv to 4 / x channel 4 / switch on fifties / x channel 4 / switch on widescreen / tune fifties tv to 5 / x channel 5 / x fifties tv / x channel 4".
Almost all of this example is the flummery of pomp and circumstance: only the first two paragraphs really do anything.
"Peers" by Elizabeth II R
A title is a kind of value. The titles are Baron, Viscount, Earl, Marquess, Duke and Prince.
A peer is a kind of man. A peer has a title. A peer is usually a Baron. Before printing the name of a peer, say "[title] ". Understand the title property as describing a peer.
The House of Lords is a room. Maltravers, Pollifax, Omnium and St Vincent are peers in the House of Lords. Omnium is a Duke. St Vincent is an Earl.
Ennobling is an action applying to one thing and one title.
Check ennobling:
if the noun is the player, say "The Sovereign is the fountain of honour, and may not be ennobled." instead;
if the noun is not a peer, say "Commoners should remain so." instead;
if the title of the noun is the title understood, say "But that is his title already." instead;
if the title of the noun is greater than the title understood, say "As he is already of the rank of [title of the noun], any such letters patent are liable to be deemed invalid, following the precedent of the Buckhurst Peerage Case (1876). Best not." instead.
Carry out ennobling:
now the title of the noun is the title understood.
Report ennobling:
say "'Whereas Our Parliament for arduous and urgent affairs concerning Us the state and defence of Our United Kingdom and the Church is now met at Our City of Westminster We strictly enjoining Command you upon the faith and allegiance by which you are bound to Us that the weightness of the said affairs and imminent perils considered (waiving all excuses) you be at the said day and place personally present with Us and with the said Prelates Great Men and Peers to treat and give your counsel upon the affairs aforesaid And this as you regard Us and Our honour and the safety and defence of the said Kingdom and Church and dispatch of the said affairs in nowise do you omit Witness Ourself at Westminster the Fifth day of November in the 43rd year of Our Reign,' you say, with unpunctuated serenity. The new [noun] bows stiffly."
Understand "dub [someone] a/an [title]" as ennobling.
Test me with "dub st vincent a baron / dub maltravers a marquess / look / examine marquess".
Our previous implementation of televisions ("Channel 1") doesn't allow the player to type things like
TUNE FIFTIES TELEVISION TO CHANNEL 4
nor does it deal with player input like
TUNE TO CHANNEL 4 ON FIFTIES TELEVISION
or
TUNE TO CHANNEL 4
where no television is specified. When we are designing commands which involve two elements (here, a television and a channel number), it's usually a good idea to allow the player to specify those elements in either order, as we saw demonstrated briefly in "New commands for old grammar".
We might, therefore, want to add a few refinements: first by defining a "[channel]" token that will accept input of the forms "[number]" and "channel [number]", and second by creating some additional "Understand" lines that will accept variant versions of the player's input.
"Channel 2"
Section 1 - Televisions in General
A television is a kind of device.
A television has a number called the channel. Understand the channel property as referring to a television. Understand "channel" as a television.
Changing the channel of it to is an action applying to one thing and one number.
Understand "tune [television] to [channel]" or "change channel of [television] to [channel]" as changing the channel of it to.
Understand "tune [something] to [channel]" or "change channel of [something] to [channel]" as changing the channel of it to.
Understand "tune to [channel] on [television]" or "change to [channel] on [television]" as changing the channel of it to (with nouns reversed).
Understand "tune to [channel] on [something]" or "change to [channel] on [something]" as changing the channel of it to (with nouns reversed).
Understand "[number]" or "channel [number]" as "[channel]".
Check changing the channel of something to:
if the noun is not a television, say "[The noun] cannot be tuned to a channel." instead.
Carry out changing the channel of something to:
now the channel of the noun is the number understood.
Report changing the channel of something to:
say "You tune [the noun] to channel [number understood]."
Instead of examining a television:
if the noun is switched off, say "[The noun] is currently turned off." instead;
let the chosen channel be the channel of the noun;
if the chosen channel is a current channel listed in the Table of Television Channels:
choose row with current channel of the chosen channel in the Table of Television Channels;
say "[output entry][paragraph break]";
otherwise:
say "Snow fills the screen of [the noun]."
Table of Television Channels
current channel
|
output
|
0
|
"The screen of [the noun] is completely black."
|
Section 2 - The Scenario
The Office is a room.
The widescreen TV is a television in the Office. The fifties TV is a television in the Office.
And we add the scenario-specific content to our Table of Television Channels; in the case of channel 13, we provide for a changing sequence of events using text variations.
Table of Television Channels (continued)
current channel
|
output
|
4
|
"A gloomy female news anchor describes the latest car bomb in Baghdad: 104 dead today, and no sign of change."
|
5
|
"A couple of contestants in spangled scarlet outfits are performing an energetic paso doble."
|
13
|
"[one of]On-screen, Ichiro is up to bat with one man on second and no outs.[or]Ichiro has singled to first and the other man is on third.[or]The next batter is in the middle of flying out.[or]Everything looks rosy until the men in black pull off a double-play and retire the side.[or]The channel has cut to a commercial.[stopping]"
|
Test me with "test one / test two".
Test one with "change channel of fifties tv to 4 / x channel 4 / switch on fifties / x channel 4 / switch on widescreen / tune fifties tv to channel 5 / x channel 5 / x fifties tv / x channel 4".
Test two with "tune to channel 13 / widescreen / tune channel 13 to channel 5 / tune channel 5 to channel 3 / widescreen / x channel 3".
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, 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:
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".