Chapter 11 - Phrases
This is an important chapter, and one I didn’t figure out for a long time.
My biggest grip with Inform 7 at the beginning was that it didn’t have functions, so I couldn’t repeat behavior without copying and pasting.
But I’ve since found it it does! They’re just called phrases and they’re so general that at first it just looks like nonsense. You can type anything you want, like
To become awesome:
now the player is in throne-room;
now the crown is worn by the player;
and then you can just type that whenever you want:
After touching the wish-stone:
become awesome;
However, this chapter doesn’t teach us how to make our own phrases, that will be much later. Instead, it teaches us about inform’s own phrases.
Section 11.1 What are phrases?
Inform has around 350 phrases built-in, and the chapters so far have already defined about 100 of those.
There are 4 kinds of phrases:
a) Phrases that do things (like void functions in other languages)
b) Phrases to decide conditions (these are like functions returning boolean values, and we’ll talk more about them later)
c) Phrases to decide a value (like functions returning a number)
d) Text substitutions (like functions returning a string)
Inform provides about 60 built-in text substitutions.
Section 11.2 is The Phrasebook.
The phrasebook is the collection of phrases Inform recognizes in the Index. I have never looked at this panel. Let’s do so!
Here’s a sample from the first tab of my phrasebook index:
Oh, so this section does show how to make a new phrase (that seems more important than the phrasebook, maybe make this section called Making new phrases instead of Phrasebook?)
Here is a simple definition of a new phrase:
To spring the trap:
say "'Sproing!' go the hinges and, with a flash of silver, the enormous blades whisk together!";
end the story.
And then you can use that phrasing whatever, but you have to type it word for word without the ‘to’:
Instead of entering the cage:
spring the trap.
Section 11.3 is pattern matching. This is where the weird ( - ) phraseology I asked about upthread comes from:
To admire (item - an object):
say "You take a long look at [item].".
This does very little, of course, but it does allow the wording to be different each time the phrase is used:
admire the diamonds;
admire Mr Cogito;
admire the honey sandwich;
Ohhhh, now I get why phrases use this weird parentheses hyphen thing instead of (called a ____) like everything else; it’s because:
The bracketed part of the definition, “(item - an object)”, tells Inform to expect an object in that position, and Inform enforces this carefully. So this definition might tell Inform what “admire the barricade” means, but not what
admire "blue cheese";
admire 63;
mean.
Technically they could have allowed something like
“To admire an object (called item)” but I wonder if the way phrases are worded is so general that the parser would get a lot of hiccups trying to figure out where the static part stopped and the variable part began.
So this is just a way to input parameters into phrases, which are Inform 7’s functions.
Another example:
To slam shut (box - an open container):
say "With great panache, you slam shut [the box].";
now the box is closed.
If you type that, then later you can type:
slam shut the Dutch armoire;
and inform will compile and print that as:
With great panache, you slam shut the Dutch armoire.
Bizarrely, you can make a phrase that only applies to one thing. If we ‘overload’ a phrase with multiple possible inputs and if something falls into more than one of the possible input categories, it only picks the more specific one.
So the example in the text is making a phrase that applies to all numbers and the the same phrase but it only applies to the number 7 (which honestly seems pretty dumb to do but kind of works like an ‘instead’ in this specific situation):
To grant (bonus - a number) points:
increase the score by the bonus.
To grant (bonus - 7) points:
say "You shiver uncontrollably."
[B]oth apply to the case of “grant 7 points”, Inform uses the second, because it’s the more specific of the two possibilities.
You can use slashes to vary the wording used in phrases (something I’ve never done):
To grant (bonus - a number) point/points: ...
or allow a word to be omitted using ‘–’:
To grant (bonus - a number) point/points/--: ...
Example 169 is Ahem:
To do/follow (chosen rule - a rule) exactly/precisely/just (N - a number) time/times:
repeat with index running from 1 to N:
follow chosen rule.
This is the throat-clearing rule:
say "'Ahem,' says [a random visible person who is not the player]."
After waiting:
do the throat-clearing rule just one time.
Instead of listening:
follow the throat-clearing rule precisely three times.
Example 170 is Ferragamo Again:
This example shows some basic ‘to say’ phrases, which are the ones I use the most often:
To say (annoyed-person - a person) gestures in irritation:
say "[The annoyed-person] sighs heavily. [run paragraph on]"
To say (annoyed-person - Vanessa) gestures in irritation:
say "[The annoyed-person] takes off her glasses and polishes them on her sleeve. [run paragraph on]".
To say (annoyed-person - Holman) gestures in irritation:
say "Holman bobs his head. [run paragraph on]"
The previous subject is a subject that varies.
Instead of talking about something for more than one turn:
if the noun is the previous subject, say "[a random visible person who is not the player gestures in irritation]Maybe you should let this one go.[line break][paragraph break]";
otherwise continue the action.
Anything defined with ‘to say’ can be thrown into any printed text, so I like to use them to trigger actions. In my game, conversational topics are physical objects called ‘quips’, so I often have stuff like this:
The description of the flight-tear is "...It issues a series of beeps, and the space in front of you to the north rips open violently, space itself tearing. The creature dives through the tear. Officer Mefe doesn't seem to notice anything at all[deliverchipless]...."
To say deliverchipless:
deliver chipless-quip;
‘Deliver’ itself is a phrase from my extensions Clues and Conversation:
To deliver (CurrentQuip - a quip):
if CurrentQuip is carried by the player:
do nothing;
otherwise:
now CurrentQuip is deliveryflagged;
And ‘deliveryflagged’ is an either/or property that gets fed into another phrase (in spoilers for length):
Summary
To clear the flags:
let somethingDelivered be 0;
repeat with currentquip running through once-delivered deliveryflagged quips:
now currentquip is not deliveryflagged;
repeat with currentquip running through deliveryflagged quips:
say "[bracket]New [if currentquip is a squip]Clue [otherwise]Topic [end if]- [currentquip][close bracket][roman type]";
say "[line break]";
now history of currentquip is "[currentquip] - [preview of currentquip][line break]";
now currentquip is carried by the emrys-weaver;
now currentquip is not deliveryflagged;
now currentquip is once-delivered;
now somethingDelivered is 1;
if the target of currentquip is nothing:
repeat with currentperson running through talkative people:
now currentperson heeds currentquip;
if somethingDelivered is 1:
If FirstClear is 0:
say "[line break][bracket]You can see your list of [HasCluesOrTopics]s by typing [CapCluesOrTopics], or just [if the number of clues carried by the player > 0]C[otherwise]T[end if].[close bracket]";
say "[line break]";
now FirstClear is 1;
if the player is not emrys-weaver:
if cluesclear is false:
say "[line break][bracket]Clues discovered during statements can be used or discussed once the statement is over.[close bracket]";
say "[line break]";
now cluesclear is true;
and finally this gets fed into an Every turn rule:
Every turn:
clear the flags
(this rigmarole is to ensure that new conversational topics are printed at the end of a given turn instead of in the middle).
Example 11.4 is The SHOWME phrase, which is similar to the SHOWME command used for testing only.
“showme” is a convenient way to see what’s going on inside a phrase which isn’t behaving as expected, or to find out the kind of a value. Here are some trickier examples. Suppose our design includes:
The matching key of the blue door is the brass Yale key.
If we then try this:
When play begins:
showme matching key of the blue door.
we get, when the story starts up,
"matching key of the blue door" = object: brass Yale key
I never do this, because you can simply add something like:
Every turn:
say "The matching key of the blue door is [the matching key of the blue door]";
I do stuff like that constantly for debugging. The main benefit of showme that I can see is that it never does anything in the final, released version of the game.
Section 11.5 is Conditions and questions.
A condition is anything which might be true or false:
Mr Kite is in Bishopsgate
the score is greater than 10
Sherlock Holmes suspects a woman
There are a few special conditions:
if in darkness
tests if the player has no light, and is different than being in a dark room (since the player might have light or be in a container).
if player consents
:
This condition is unusual in doing something and not simply making a silent check: it waits for the player to type YES (or Y) or NO (or N) at the keyboard, and then is true if the answer was yes.
You can turn any condition into a boolean with the following phrase:
whether or not (a condition) … truth state
For instance, you can say:
let victory be whether or not all the treasures are in the cabinet;
and then subsequently:
if victory is true, ...
I find this personally a bit disturbing, to be honest. It feels like Inform I’ve seen and used before but slightly off, like a cat you think is your own and you go to pet it before you realize it’s someone else’s cat that’s wandered by your house.
You can also make truth states that vary:
Salvation earned is a truth state that varies.
I used to use 0/1 variables because I didn’t know truth states existed, so I’d be like FlyingFlag is a number that varies. FlyingFlag is 0.
Now I just say
FlyingFlag is a truth state that varies. FlyingFlag is false.
It’s logically the same, but helps me remember what the numbers stand for.
Example 171 is Proposal:
This has two different ways to handle yes/no questions: the ‘player consents’, and regular conversation.
Mr Spruce is a man in the Conservatory. Mr Spruce can be apprehensive or calm. Mr Spruce is calm. Mr Spruce can be handsome or ugly.
When play begins:
say "Do you like Mr Spruce? ";
if player consents, now Spruce is handsome;
otherwise now Spruce is ugly;
say paragraph break.
Instead of saying yes in the presence of an ugly apprehensive Mr Spruce:
now Mr Spruce is calm;
say "Remembering what your mother said to you about the stock exchange and Dear Papa, you close your eyes and accept Mr Spruce.";
end the story saying "Alas for your maiden hopes."
Instead of saying yes in the presence of a handsome apprehensive Mr Spruce:
now Mr Spruce is calm;
say "You are silent with delight for a moment before you say yes, yes!";
end the story saying "How Genevieve Stubbs will cry!"
Instead of saying no in the presence of an ugly apprehensive Mr Spruce:
now Mr Spruce is calm;
say "Gently you inform Mr Spruce that it is impossible. He seems less deflated than you had expected.";
end the story saying "Odd, that..."
Instead of saying no in the presence of a handsome apprehensive Mr Spruce:
now Mr Spruce is calm;
say "You lower your eyes and refuse petulantly, hoping to stir him to a more ardent repetition of these same requests. But then -- alack! -- he says 'I see how it is!' in a strangled voice, and strides from the room!";
end the story saying "A fatal error!"
Section 11.6 is If, which is a Rudyard Kipling…wait, never mind, it’s just the regular if statement from programming.
You can use ‘if’ in two different ways:
if (a condition) , (a phrase)
or:
if (a condition):
So, all in one line with a phrase following or in a block format. If you want to type ‘if not…’, just use Unless:
unless (a condition) , (a phrase)
or:
unless (a condition):
Section 11.7 is Begin and End. It talks about two ways to group complex if statements in blocks.
The first is as so, using indentation:
To comment upon (whatever - a thing):
if whatever is transparent, say "I see right through this!";
if whatever is an open door:
say "Oh look, an open door!";
if whatever is openable, say "But you could always shut it."
The second is to use ‘begin’ and ‘end if’:
To comment upon (whatever - a thing):
if whatever is transparent, say "I see right through this!";
if whatever is an open door
begin;
say "Oh look, an open door!";
if whatever is openable, say "But you could always shut it.";
end if.
I don’t use this, but I’ve seen some people do and it confused me.
It also claims that Python is named after Monty Python’s Flying Circus, which I am deliberately not going to look up for confirmation.
Example 172 is Matreshka:
This example has nothing to do with the material in the section. Instead of using Begin and If in an if statement, it introduces a ‘while’ statement with no explanation in the commentary:
Carry out ransacking:
while the player can see a closed openable unlocked container (called target):
say "[target]: [run paragraph on]";
try opening the target.
Although it does have an if statement earlier (still not using Begin or If):
Check ransacking:
if the noun is not the location, say "You can hardly search [the noun] from here." instead.
Example 173 is the princess and the pea, which also uses a while statement. Was this section originally a section on while statements that got rewritten, but the examples just never got changed?
Check ransacking:
if the noun is not the location, say "You can hardly search [the noun] from here." instead.
Section 11.8 is called ‘otherwise’, which is exactly equivalent to ‘else’ in most programming languages. You can use it in many ways (including just typing ‘else’):
otherwise if (a condition)
or:
otherwise unless (a condition)
or:
otherwise (a phrase)
or:
else if (a condition)
or:
else unless (a condition)
or:
else (a phrase)
So, for example:
if N is 2, say "Hooray, N is 2!";
otherwise say "Boo, N is not 2...";
So this is pretty bog standard programming. If you’ve programmed with any language every, you’ve probably done If/Else statements. If inform is your first language, then this section does a pretty good job of explaining it.
You can also use ‘switches’ in Inform like this:
if the dangerous item is:
-- the electric hairbrush:
say "Mind your head.";
-- the silver spoon:
say "Steer clear of the cutlery drawer."
and you can use ‘otherwise’ for exactly one of these options:
if N is:
-- 1: say "1.";
-- 2: say "2.";
-- otherwise: say "Neither 1 nor 2.";
I don’t use this, but I’ve seen people using it recently on this forum, and I think it looks neat!
Example 174 is Numberless:
When play begins:
let N be a random number between 1 and 5;
if N is 1:
say "N is one.";
otherwise if N is 2:
say "N is two.";
otherwise if N is 3:
say "N is three.";
otherwise:
say "N is more than the number of your toes."
When play begins:
let Y be a random number between 6 and 10;
if Y is:
-- 6: say "Six is the magic number!";
-- 7: say "The number of the day is seven!";
-- otherwise: say "Today's magic number is boring."
When play begins:
let X be a random number between 11 and 14;
if X is a number listed in the Table of Switching, say "[output entry][paragraph break]";
otherwise say "X is greater than the number of your noses!"
Table of Switching
number
output
11
"X is eleven!"
12
"X is twelve!"
13
"X is thirteen!"
So three different ways of handling if statements with text responses.
Section 11.9 is ‘While’, which has no examples. So it looks like the examples for 11.9 accidentally got moved to section 11.7, and that should probably be reported as a bug.
So a while loop just gets repeated forever until it’s no longer true:
while someone (called the victim) is in the Crypt:
say "A bolt of lightning strikes [the victim]!";
now the victim is in the Afterlife;
These are dangerous and should be tested thoroughly to avoid infinite loops. The example in the text is amusing:
while eggs is eggs:
say "again and ";
which, as sure as eggs is eggs (which is very sure indeed), writes out
again and again and again and again and again and ..
You can use the indentation method or the begin/end method:
while ...
begin;
...
end while.
Section 11.10 is Repeat, which is a for loop, and something I find very useful indeed. Repeat loops always have a definite ending, unlike while loops.
This section does the most basic kind of Repeat loop, which just goes through consecutive values in any kind of enumerated value:
repeat with (a name not so far used) running from (arithmetic value) to (arithmetic value)
or:
repeat with (a name not so far used) running from (enumerated value) to (enumerated value):
Examples include:
repeat with counter running from 1 to 10:
repeat with moment running from 4 PM to 4:07 PM:
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
I don’t think I ever used this version of repeat.
There is a more complicated example:
To plot a grid with size (S - a number):
repeat with x running from 1 to S:
say "Row [x]:";
repeat with y running from 1 to S:
say " [y]";
say "."
This section is another of the ‘basic programming language 101’ sections. So maybe this chapter 11 would be a good introduction for ‘Inform for programmers’, since this chapter has functions, if statements, else statements, while and for loops, which are most of the main things you want to do in almost any programming language. This is as opposed to the ‘Basic Actions’ , ‘Change’ and ‘Scene’ sections, which I think are good for non-technical introductions and/or actual game making.
Example 175 is Wonka’s Revenge:
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.
Spinning is an action applying to one thing.
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.
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.
11.11 is Repeat running through
This section has my preferred form of repeat loops. I have 53 loops in my game of the form ‘repeat with ___ running through’.
You use it like this:
repeat with item running through open containers:
and then you write code including whatever name you gave your variable (here, ‘item’).
repeat with suspect running through the men who are in a lighted room:
say "[The suspect] is in [the location of the suspect].";
You can’t repeat through all numbers but can repeat through all 1440 times in the day.
Example 176 is Strictly Ballroom:
A person can be alert or occupied. A person is usually alert.
When play begins:
now the player is occupied.
Dance is a kind of value. The dances are waltzes, polkas, cha-chas, charlestons, fox-trots, tangos, lambadas, and two-steps.
The current round is a dance that varies.
Manner is a kind of value. The manners are swiftly, primly, energetically, suavely, seductively, elegantly, and badly.
Every turn: now the current round is a random dance.
Every turn:
repeat with dancer running through people who are not the player:
if dancer is alert:
now dancer is occupied;
let partner be a random alert person who is not the dancer;
if partner is a person:
now partner is occupied;
say "[The dancer] [the current round][if a random chance of 1 in 5 succeeds] [a random manner][end if] with [partner]. ";
otherwise:
say "[paragraph break][The dancer] is forced to be a wallflower. Poor [dancer]. ";
say paragraph break.
I use it for a device that has a lockpick mode:
Report tuning it to:
say "You set [the noun] to [tool-mode understood].";
if the curious-tool is lockpick:
repeat with current running through lockable doors:
now curious-tool unlocks current;
now curious-tool unlocks treasure-case;
now curious-tool unlocks arthur-briefcase;
say "[bracket]To use the lockpick, simple UNLOCK a locked door WITH the tool.[close bracket][line break]";
otherwise:
repeat with current running through lockable doors:
now curious-tool does not unlock current;
now curious-tool does not unlock treasure-case;
if the curious-tool is flashlight:
now curious-tool is lit;
say "The tool brightens up the surrounding area considerably.";
otherwise:
now curious-tool is not lit;
Section 11.12 is Next and Break. These are ways to skip things in a loop or to stop a loop.
For instance:
repeat with X running from 1 to 10:
if X is 4, next;
say "[X] ".
produces the text "1 2 3 5 6 7 8 9 10 ", with no “4” because the “say” phrase was never reached on the fourth repetition.
Break is used similarly:
repeat with X running from 1 to 10:
if X is 7, break;
say "[X] ".
produces the text "1 2 3 4 5 6 ", with nothing after “6” because the loop was broken at that point. The “say” wasn’t reached on the 7th repetition, and the 8th, 9th and 10th never happened.
I’ve never used either one, although I can see the use. These are also pretty standard in most programming languages.
Section 11.13 is ‘Stop’. This is similar to break, but used in any phrase:
To judge the score:
if the score is 0, stop;
say "The score is [score in words] more than it was a half-hour ago."
In the case when the score is 0, the “stop” ends the phrase immediately, so that the subsequent text is printed only if the score is not 0.
“Stop” can also be used in action rules, though this is not very good style - it’s clearer to use “stop the action”, which is exactly equivalent.
Section 11.14 is Phrase options. These are just functions with extra parameters:
To go hiking, into the woods or up the mountain:
if into the woods, say "Watch out for badgers.";
if up the mountain, say "Better take your compass.";
say "You go hiking."
and then you can type any of these three:
go hiking;
go hiking, into the woods;
go hiking, up the mountain;
I’ve never used this, but I’d imagine it’s useful if you have several similar phrases.
The most complex example of these parameters in the text are in the ‘list the contents of’ phrase, which is defined in the standard rules as:
To list the contents of (something - an object), with newlines, indented, as a sentence, including contents, including all contents, giving inventory information, giving brief inventory information, using the definite article, listing marked items only, prefacing with is/are, not listing concealed items, suppressing all articles and/or with extra indentation: ...
Example 177 is Equipment List:
Inventory listing style is a kind of value. The inventory listing styles are tall, wide, curt, minimal, divided tall, and divided wide. Current inventory listing style is an inventory listing style that varies.
Instead of taking inventory when current inventory listing style is tall:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying: [line break]";
list the contents of the player, with newlines, indented, giving inventory information, including contents, with extra indentation.
Instead of taking inventory when current inventory listing style is wide:
if the number of things enclosed by the player is 0, say "You are empty-handed." instead;
say "You are carrying ";
list the contents of the player, giving inventory information, as a sentence, including contents;
say "."
There is quite a bit more than that, but it gives a taste of this complex example. I rewrite inventory rules in my Conservation extension since I model conversation topics as physical objects. I like that method because you don’t have to deal with scope (you’re either carrying the topic or not) and can assign properties easily to the topics, which I feel is harder to do when topics are just chunks of text.
11.15 is Let and temporary variables. This is just a way to make temp, local variables that only last in the current phrase:
let outer bull be 25;
let the current appearance be "reddish brown";
let the special room be Marley Wood;
You can also make temp variables without an initial value by specifying a kind:
let inner bull be a number;
Example 178 doesn’t use temporary variables at all. Instead, it just shows you can vary text with cycling substitutions, if statements, or values. One part is like this:
Tint is a kind of value. The tints are green, aquamarine and darkish purple.
The wallpaper is fixed in place in the Hôtel. The wallpaper has a tint. "In this light, the wallpaper has a distinctly [tint of the wallpaper] wash. [if the tint of the wallpaper is darkish purple]You particularly dislike purple.[end if]"
So the text has no actual examples of let statements in this section. Here’s one I have, where I use temporary variables to avoid complicated conditional statements:
Before physicality when the noun is a climbing-rock:
let tempmax be climbingheight plus 1;
let tempmin be climbingheight minus 1;
if rockheight of the noun > tempmax:
say "That's too high above you!" instead;
otherwise if rockheight of the noun < tempmin:
say "That's too far below you!" instead;
11.16 is New conditions, new adjectives.
I only started using this for the first time on my current game. You can make new conditional statements with the phrase ‘to decide whether’ or ‘to decide if’, and the phrases ‘decide yes’ and ‘decide no’. Once the game hits a ‘decide yes’ or ‘decide no’, it’s done:
To decide whether danger lurks:
if in darkness, decide yes;
if the Control Room has been visited, decide no;
decide yes.
You can also just say ‘yes’ instead of ‘decide yes’.
I use this for complex conditionals, like this in my game (I’m probably going to replace this with ‘move without printing a room description’ at some point, although this does work just fine):
The room description heading rule does nothing when looking is stupid.
The room description body text rule does nothing when looking is stupid.
The offer items to writing a paragraph about rule does nothing when looking is stupid.
To decide whether looking is stupid:
if the climbing-wall is nowhere, decide no;
if the player is not enclosed by pride-room, decide no;
if the current action is not looking, decide no;
decide yes;
We can also define adjectives:
Definition: a supporter is occupied if it is described and something is on it.
And, a question I had earlier that was answered by Zed, I think, you can do this in a multi-line way:
Definition: a supporter is occupied:
if it is undescribed, no;
if something is on it, yes;
no.
Example 179 is Owen’s Law, which provides a nice way of deciding what ‘in’ and ‘out’ should do:
A room can be indoors or outdoors. A room is usually indoors.
Definition: a room is outward:
if it is not adjacent, no;
if it is indoors and the location is outdoors, no;
if it is outdoors and the location is indoors, yes;
if the number of rooms adjacent to it is greater than the number of rooms adjacent to the location, yes;
otherwise no.
Definition: a room is inward:
if it is not adjacent, no;
if it is outdoors and the location is indoors, no;
if it is indoors and the location is outdoors, yes;
if the number of rooms adjacent to it is less than the number of rooms adjacent to the location, yes;
otherwise no.
It then has some extra code to help with this.
Section 11.17 is Phrases to decide other things. I’ve never used this.
To decide which treasure is the grand prize:
if the Dark Room has been visited, decide on the silver bars;
decide on the plover's egg.
For those familiar with other languages, ‘to decide whether’ and ‘to decide with’ are just functions, and ‘decide on’ is the same as ‘return’.
The ‘function name’ here is ‘grand prize’, so you just use it wherever you want:
if taking the grand prize, ...
I’m not sure how one would write something with an input and an output
(like To decide which color is the favorite-color of (currentperson - a person)
?)
You can nest these kinds of things:
To decide if time is short:
if the time of day is after 10 PM, decide on true;
...
decide on whether or not Jennifer is hurried.
Example180 is Witnessed 2:
To decide what number is meter setting:
if the meter is switched off, decide on 0;
if a ghost is touchable, decide on 35;
if a ghost is visible, decide on 12;
decide on 0.
Example 181 is A Haughty Spirit:
To decide what number is the distance (first place - a room) rises above (second place - a room):
let the total distance be the number of moves from the first place to the second place;
if the total distance is less than 1, decide on 0;
let count of down moves be 0;
let count of up moves be 0;
let next place be the first place;
repeat with counter running from 1 to the total distance:
let the way be the best route from the next place to the second place;
if the way is down, let count of down moves be the count of down moves plus 1;
if the way is up, let the count of up moves be the count of up moves plus 1;
let next place be the room the way from next place;
let the decision be the count of down moves minus the count of up moves;
decide on the decision.
(This is a more elegant solution to my rock-climbing example earlier).