| 11.16. New conditions, new adjectives |
We can create new conditions by defining a phrase with "to decide whether" (or equivalently "to decide if"):
To decide whether danger lurks:
if in darkness, decide yes;
if the Control Room has been visited, decide no;
decide yes.
If the player is indeed in darkness, the decision is "yes" because the "decide yes" stops the process right there. We can now write, for instance,
if danger lurks, ...
In fact, "danger lurks" is now a condition as good as any other, and can be used wherever a condition would be given. Rules can apply only "when danger lurks", for instance.
yes
or: decide yes
This phrase can only be used in the definition of a phrase to decide whether a condition holds. It ends the decision process immediately and makes the condition true.
|
no
or: decide no
This phrase can only be used in the definition of a phrase to decide whether a condition holds. It ends the decision process immediately and makes the condition false.
|
We can also supply definitions of adjectives like this. So far, new adjectives have been defined like so:
Definition: a supporter is occupied if it is described and something is on it.
If we want to give a definition which involves more complex logic, we can use a special form allowing us to make arbitrary decisions. In this longer format, the same definition would look like so:
Definition: a supporter is occupied:
if it is undescribed, decide no;
if something is on it, decide yes;
decide no.
Here "it" refers to the supporter in question. Note that there are now two colons in this sentence, one after "Definition", the other after the clause being defined. But that apart, it's a phrase like any other: it must end in "yes" or "no" just as the "danger lurks" example must. "Decide no" and "decide yes" are needed so often that they can be abbreviated by leaving out "decide":
Definition: a supporter is occupied:
if it is undescribed, no;
if something is on it, yes;
no.
Suppose we want the game to interpret "GO OUT" as "move towards an outdoors room, or towards a room with more exits than the current room", while "GO IN" means "move toward a room with fewer exits, or towards an indoors room". Thus going in repeatedly within a building would lead towards dead-ends, while going out repeatedly would lead towards the center of the building and then towards an exit to the outside world.
We start by encoding these rules as definitions:
"Owen's Law"
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.
Instead of going nowhere when the noun is outside: try exiting.
Instead of exiting when the player is in a room:
if at least one room is outward:
let the destination be a random outward room;
let the way be the best route from the location to the destination;
say "(that is, [way])[command clarification break]";
try going the way instead;
otherwise:
say "It's not entirely obvious which way you mean. ";
carry out the listing available exits activity.
Instead of going inside when the room inside from the location is not a room and at least one room is inward:
if more than one room is inward:
carry out the listing available exits activity;
otherwise:
let the destination be a random inward room;
let the way be the best route from the location to the destination;
say "(that is, [way])[command clarification break]";
try going the way instead.
Instead of going nowhere:
carry out the listing available exits activity.
This "listing available exits" is a refinement borrowed from a future chapter, which allows us to specify special listing and printing rules:
Listing available exits is an activity.
Rule for listing available exits:
if going inside and an adjacent room is inward:
say "From here 'in' could reasonably mean [a list of adjacent inward rooms].";
rule succeeds;
if exiting and an adjacent room is outward:
say "From here 'out' could reasonably mean [a list of outward adjacent rooms].";
rule succeeds;
say "From here you can go [a list of adjacent rooms]."
Before printing the name of a room (called the target) while listing available exits:
let aim be the best route from the location to the target;
say "[aim] to the ".
Rule for printing the name of an unvisited room which is not the location:
say "unknown location".
Dune is an outdoors room. "Hundreds of feet of dune stretch west to the beach, crisscrossed with dune-buggy tracks and the footprints of birds. To the east is a low-lying, boxy concrete installation."
Ocean Shores Military Installation is east of the Dune. It is an outdoors room. "The World War II emplacements, built in case of Japanese invasion, have never been destroyed, though with all the weapons and furnishings gone it is difficult to make much sense of the original structure. A doorway leads west into concrete-lined darkness; a rusty but reliable ladder ascends to a walkway overlooking the sea."
Walkway is above Ocean Shores Military Installation. "From here you have a long view of the dunes and the Pacific Ocean, complete with the rotting hull of a long-stranded vessel."
Dark Echoing Room is inside from Ocean Shores Military Installation. Dank Dripping Room is east of Dark Echoing Room. Narrow Room is south of Dark Echoing Room. Small Sealed Chamber is north of Dark Echoing Room. Room Smelling of Animal Urine is north of Dank Dripping Room. The description of a room is usually "It is dark in here, and feels unsafe."
Test me with "e / u / d / in / s / out / n / out / e / in / out / out / out".
|