§13.11. Indirect relations
We have already seen, in the chapter on Descriptions which is a forerunner of this one, that Inform provides not only "adjacent" as a way of seeing if one room is directly connected to another, but also "the best route from A to B", which allows us to see if any sequence of moves connects them.
Something similar - in fact, simpler - is allowed for any relation between objects. Suppose we would like to go sledging: we can go downhill, but not up. Some quite distant places may be reachable, while others close by may not be, even if lower than us, because they would involve climbing again at some point. The following would implement this:
The verb to overlook means the overlooking relation.
The Garden overlooks the Shrubbery. The Folly overlooks the Garden. The Shrubbery overlooks the Sundial Plot. The Old Ice House overlooks the Garden.
After looking:
say "This wintry vantage point overlooks [the list of rooms overlooked by the location].";
let the way be the next step via the overlooking relation from the location to the Sundial Plot;
if the way is a room, say "To sledge downhill to the Sundial, aim for [the way].";
otherwise say "It is not possible to sledge downhill to the Sundial."
Here we're making use of:
next step via (relation of values to values) from (object) to (object) ... object
This phrase tries to find a shortest route between the two given endpoints, using the given relation of objects to determine single steps. Example:
next step via the overlooking relation from the Folly to the Chinese Lake
The result is the special object value "nothing" if the two endpoints are the same or if no route exists.
number of steps via (relation of values to values) from (object) to (object) ... number
This phrase tries to find the length of a shortest route between the two given endpoints, using the given relation of objects to determine single steps. Example:
number of steps via the overlooking relation from the Folly to the Chinese Lake
The result is 0 if the two endpoints are the same, or -1 if no route exists.
Another example would be the "six degrees of separation" game, where it is claimed that any two people on Earth are connected by a sequence of up to six acquaintances. In an Inform implementation, we might talk about "the next step via the friendship relation from George Bush to Saddam Hussein", for instance, a phrase likely to evaluate to Donald Rumsfeld, and then
the number of steps via the friendship relation from George Bush to Saddam Hussein
would be... but that would be telling.
As with route-finding through the map, finding "the next step via" a relation can be slow. For instance, suppose we have dozens of articles of clothing all partially revealing each other, connected by two relations - overlying and underlying. Then "the next step via" these relations allows us to establish what can be worn on top of what else. If we need to calculate this often, and there are enormous wardrobes of clothes to choose from, speed starts to matter.
Once again there is a choice of algorithms: "fast" and "slow", where "fast" needs much more memory. To make route-finding for a given relation "fast", we have to declare it that way:
Overlying relates various garments to various garments with fast route-finding.
Overlapping relates various garments to each other with fast route-finding.
Otherwise, the "slow" method will be used.
This "with fast route-finding" note can only be added to various-to-various relations. (Although route-finding through various-to-one and one-to-various relations is fully supported, it exploits the relative simplicity of these problems to use a more efficient algorithm than either "fast" or "slow".)
See Adjacent rooms and routes through the map for route-finding through the map rather than a relation
![]() | Start of Chapter 13: Relations |
![]() | Back to §13.10. Defining new prepositions |
![]() | Onward to §13.12. Relations which express conditions |
Suppose that we have a core set of issues we want to be able to bring up with all the characters, and we want characters to draw intelligent connections between different conversation topics. We will need some model of how things relate to one another, so:
And if we wanted to offer the player some hints about angles he could pursue:
For that matter, we could use the same system to have characters make sense of any physical evidence the character shows them:
Now we can define what gets said when the subject is changed, regardless of whether the segue was introduced in speech or by a shown object. Since rows are blanked after use, the speaker will never repeat herself; if we provide more than one line about the same pair of topics, the first one will be used, then the second, and so on, until the table runs out:
If we had more than one character in the scenario, we could provide multiple tables, but this will do to demonstrate the idea. Of course, we can override specific instances, if we want the character always to say the same thing regardless of how we came to this point:
We would have to be careful about this system, since we have applied a various-to-various relation to every single object in the game. In practice it would probably be wisest to restrict it a bit, with judicious definitions of kind and so on. |
|
Suppose that we have a core set of issues we want to be able to bring up with all the characters, and we want characters to draw intelligent connections between different conversation topics. We will need some model of how things relate to one another, so:
And if we wanted to offer the player some hints about angles he could pursue:
For that matter, we could use the same system to have characters make sense of any physical evidence the character shows them:
Now we can define what gets said when the subject is changed, regardless of whether the segue was introduced in speech or by a shown object. Since rows are blanked after use, the speaker will never repeat herself; if we provide more than one line about the same pair of topics, the first one will be used, then the second, and so on, until the table runs out:
If we had more than one character in the scenario, we could provide multiple tables, but this will do to demonstrate the idea. Of course, we can override specific instances, if we want the character always to say the same thing regardless of how we came to this point:
We would have to be careful about this system, since we have applied a various-to-various relation to every single object in the game. In practice it would probably be wisest to restrict it a bit, with judicious definitions of kind and so on. Suppose that we have a core set of issues we want to be able to bring up with all the characters, and we want characters to draw intelligent connections between different conversation topics. We will need some model of how things relate to one another, so:
And if we wanted to offer the player some hints about angles he could pursue:
For that matter, we could use the same system to have characters make sense of any physical evidence the character shows them:
Now we can define what gets said when the subject is changed, regardless of whether the segue was introduced in speech or by a shown object. Since rows are blanked after use, the speaker will never repeat herself; if we provide more than one line about the same pair of topics, the first one will be used, then the second, and so on, until the table runs out:
If we had more than one character in the scenario, we could provide multiple tables, but this will do to demonstrate the idea. Of course, we can override specific instances, if we want the character always to say the same thing regardless of how we came to this point:
We would have to be careful about this system, since we have applied a various-to-various relation to every single object in the game. In practice it would probably be wisest to restrict it a bit, with judicious definitions of kind and so on. |