# Relation holding by steps via two relations?

I have two relations, requirement and suggestion, and I want Inform to be able to calculate another relation via steps taking through either. Here is my code:

[code]A whatsit is a kind of thing.

Requirement relates various whatsits to various whatsits.
The verb to require (it requires, they require, it required, it is required, it is requiring) implies the requirement relation.

Suggestion relates various whatsits to various whatsits.
The verb to suggest (it suggests, they suggest, it suggested, it is suggested, it is suggesting) implies the suggestion relation.[/code]
I want a transitive relation for these. I know I can do:

```Indirect-requirement relates various themes to various themes. The verb to i-require (it i-requires, they i-require, it i-required, it is i-required, it is i-requiring) implies the indirect-requirement relation.```
and similarly for suggestion. But if I have the set-up:

```A1, A2, A3, B1, B2, and B3 are whatsits. A1 requires A2. A2 requires A3. A3 suggests B1. B1 suggests B2. B2 suggests B3.```
and I want Inform to recognize the connection between A1 and B3 (that is, A1 => A2 => A3 by requirement and then A3 => B1 => B2 => B3 by suggestion), how can I do that?

I have tried the following which does not work:

``Connection relates a whatsit (called A) to a whatsit (called B) when the number of steps via the requirement relation from A to B > 0 or the number of steps via the suggestion relation from A to B > 0.``

I don’t see an easy way to do this, as Inform doesn’t support route-finding through implicit relations.

If these relations are static, you could precalculate the connection relation at startup: go through all the whatsits and set every pair connected if its either suggested or required.

Can you brute force it? This seems to be working:

[code]No-where is a room.

A whatsit is a kind of thing.

Requirement relates various whatsits to various whatsits.
The verb to require (it requires, they require, it required, it is required, it is requiring) implies the requirement relation.

Suggestion relates various whatsits to various whatsits.
The verb to suggest (it suggests, they suggest, it suggested, it is suggested, it is suggesting) implies the suggestion relation.

A1, A2, A3, B1, B2, B4, B5, and B3 are whatsits.
A1 requires A2. A2 requires A3.
A3 suggests B1.
B1 suggests B2. B2 suggests B3.
B4 suggests B5.

To decide whether (A - a whatsit) is connected to (B - a whatsit):
if the next step via the suggestion relation from A to B is not nothing:
decide yes;
if the next step via the requirement relation from A to B is not nothing:
decide yes;
repeat with C running through whatsits:
if the next step via the suggestion relation from A to C is not nothing and the next step via the requirement relation from C to B is not nothing, decide yes;
if the next step via the requirement relation from A to C is not nothing and the next step via the suggestion relation from C to B is not nothing, decide yes;
decide no.

Connection relates a whatsit (called A) to a whatsit (called B) when A is connected to B. The verb to be stuck to implies the connection relation.

Booping is an action applying to two visible things. Understand “boop [any thing] with [any thing]” as booping.

Carry out booping:
if the noun is not a whatsit or the second noun is not a whatsit:
say “Only whatsits can be booped.”;
otherwise:
if the noun is stuck to the second noun:
say “[Noun] is connected to [second noun].”;
otherwise:
say “[Noun] is not connected to [second noun].”[/code]

The connection relation isn’t doing any work here (you could have “is connected to” instead of “is stuck to” in the carry out booping rule), but I added it to show that a relation seems to be getting defined here. It’s not symmetric or reflexive, but you didn’t say it should be (and those can be added easily).

I could be misunderstanding the question, though – I’ve never quite been able to figure out what Inform doesn’t support here.

You do have to be careful; the code above will only allow one alteration in the relation by which the whatsits are connected (though maybe that’s what you wanted). For instance, A1 and B1 in```A1, A2, A3, B1 are whatsits. A1 requires A2. A2 suggests A3. A3 requires B1.``` are not reported as connected.

If you add the code```When play begins: showme the next step via the connection relation from A1 to A2.``` you can see what Zarf was talking about. `The next step via...'' will throw runtime problems when used with a relation defined by`… relates … to … when …’’ This is why one can’t simply say``` Connection relates a whatsit (called A) to a whatsit (called B) when A suggests B or A requires B. ```

facepalm Of course. Yeah, I don’t think my hack does what the original poster wants, then.

Ah, OK then. That’s the missing thing that I wasn’t following.

At the risk of necro-posting, I happened across this while looking for something else and thought it was worth resurrecting since it has a high number of views (implying that people keep looking for a solution). This seems to work in Inform 6M62:

Indirect Relations
``````"Indirect Relations"

Place is a room.

A whatsit is a kind of thing.

Requirement relates various whatsits to various whatsits.
The verb to require implies the requirement relation.
[A3 -> A2 -> A1]

Suggestion relates various whatsits to various whatsits.
The verb to suggest implies the suggestion relation.
[A3 -> B1 -> B2 -> B3]

A1, A2, A3, B1, B2, and B3 are whatsits. A2 requires A1. A3 requires A2. A3 suggests B1. B1 suggests B2. B2 suggests B3.

[and I want Inform to recognize the connection between A1 and B3 (that is, A1 => A2 => A3 by requirement and then A3 => B1 => B2 => B3 by suggestion), how can I do that?]

Transitive requirement relates a whatsit (called Y) to a whatsit (called X) when the number of steps via the requirement relation from Y to X is at least one. The verb to depend upon means the transitive requirement relation. The verb to enable means the reversed transitive requirement relation.

Transitive suggestion relates a whatsit (called X) to a whatsit (called Y) when the number of steps via the suggestion relation from X to Y is at least one. The verb to recommend means the transitive suggestion relation.

[The next two relations seem the same but are significantly different in terms of how they are interpreted by Inform, which sets up an order of operations for evaluating any given relation.]

Sustenance [poor name] relates a whatsit (called X) to a whatsit (called Z) when ((any whatsit (called Y) depends upon X) and (Y recommends Z)). The verb to sustain means the sustenance relation.

Reliance [also a poor name] relates a whatsit (called Z) to a whatsit (called X) when ((Z is recommended by any whatsit (called Y)) and (Y depends upon X)). The verb to rely upon means the reliance relation.

[I'm not 100% sure that what this does is what you wanted, but, if not, you can probably modify it into what you want.]

Indirect requirement relates a whatsit (called Z) to a whatsit (called X) when Z depends upon X or X recommends Z or X sustains Z or Z relies upon X. The verb to indirectly-require means the indirect requirement relation.

Analyzing is an action applying to one visible thing. Understand "analyze [any thing]" as analyzing.

Report analyzing:
say "[The noun] requires [the list of things required by the noun].";
say "[The noun] is required by [the list of things requiring the noun].";
say "[The noun] depends upon [the list of things depended upon by the noun].";
say "[The noun] enables [the list of things enabled by the noun].";
say "[The noun] suggests [the list of things suggested by the noun].";
say "[The noun] is suggested by [the list of things suggesting the noun].";
say "[The noun] recommends [the list of things recommended by the noun].";
say "[The noun] is recommended by [the list of things recommending the noun].";
say "[The noun] sustains [the list of things sustained by the noun].";
say "[The noun] is sustained by [the list of things sustaining the noun].";
say "[The noun] relies upon [the list of things relied upon by the noun].";
say "[The noun] is relied upon by [the list of things relying upon the noun].";
say "[bold type][The noun] indirectly requires [the list of things indirectly-required by the noun].[roman type][line break]";
say "[bold type][The noun] is indirectly required by [the list of things indirectly-requiring the noun].[roman type][line break]";
do nothing.

Test me with "analyze a1 / analyze a2 / analyze a3 / analyze b1 / analyze b2 / analyze b3".
``````

which yields:

``````>ANALYZE A1
...
A1 indirectly requires nothing.
A1 is indirectly required by A2, A3, B1, B2 and B3.

>ANALYZE A2
...
A2 indirectly requires A1.
A2 is indirectly required by A3, B1, B2 and B3.

>ANALYZE A3
...
A3 indirectly requires A1 and A2.
A3 is indirectly required by B1, B2 and B3.

>ANALYZE B1
...
B1 indirectly requires A1, A2 and A3.
B1 is indirectly required by B2 and B3.

>ANALYZE B2
...
B2 indirectly requires A1, A2, A3 and B1.
B2 is indirectly required by B3.

>ANALYZE B3
...
B3 indirectly requires A1, A2, A3, B1 and B2.
B3 is indirectly required by nothing.
``````
1 Like