Extracting valid commands from a zmachine file?

Hi everyone,

Is there a way to extract all the valid commands from a zmachine file? We’re building an Amazon Alexa Skill* wrapper for zmachine games (using Frotz), but right now we have to manually list each of the valid commands.

Ideally, a developer could take their game and turn it into a skill with minimal effort. Any ideas?

*Skills are voice apps


Hmm. What do you mean by “valid”? Anything that does not result in an “I didn’t understand that” response or similar?

What do you mean by commands? Just the verbs? All combinations of all possible verbs and all possible nouns, so, for instance for a red door, you’d have, “look door”, “examine door,” “x door”, “take door”, “get door”, (a bunch more stuff using “door”), and then “look red”, “examine red”; “x red”, ( a bunch more stuff using “red”), and so on for every object?

Does it have to come from a compiled game or can it be done with the help of the source code?

Unfortunately not.

While it’s possible to get all of the words from the dictionary, how those can be parsed makes up a significant chunk of the code in a Z-machine file. Listing them all out would run into a combinatorial explosion problem very quickly: Zork recognized 405 adjectives, 935 verbs, and 1022 nouns (based on a quick count from this file. That gives almost a million possible commands of the form VERB NOUN. Add in a million more for VERB THE NOUN, and then you have VERB [THE] NOUN TO [THE] NOUN (“tie the rope to the railing”), and then adjectives, and possessives…

If that weren’t bad enough, some games use numbers and non-dictionary words (see Spellbreaker) which wouldn’t even be counted in such an estimate.

I’m not sure how Skills work, but can they be trained on individual words rather than full phrases?

Skills have the concept of “slots” which are values that can be inserted into a phrase. Phrases are assigned to “intents” which are specific commands sent to the skill to execute. All of the speech recognition and Natural Language parsing is handled by the Alexa service and sent to the skill in a structured format.

For example, if you define a {COLOR} slot containing “RED”, “BLUE”, “GREEN” you could have

MyColorIntent the color is {COLOR}
MyColorIntent my color is {COLOR}
MyColorIntent {COLOR} is my favorite

One key detail is that the slot values aren’t strictly limited to what you entered. It’s more like a guideline for the speech recognizer. In the example above, saying “the color is yellow” would usually still work.

If I can extract all the nouns, verbs and adjectives, then I can create custom slots for each of those and the speech recognizer will work fine.

IFCommandIntent {VERB} the {NOUN}
IFCommandIntent {VERB} the {ADJECTIVE} {NOUN}
etc etc

If all the words can be extracted and grouped into verb, noun etc. from the source that would be best, I’m just trying to avoid having to do it manually.

In that case, Infodump from the Z-tools package is probably what you want. It gives you the full dictionary, plus as much of the grammar as it can decipher. There’s also Zorkword, another tool for that purpose.

That looks great! Thanks a ton.

I’ll post here once we have something ready. :slight_smile:

I found this post as I was curious as to how many verbs were supported in TA/IF games. Anyway 935 verbs seemed much higher than I had expected for such an early game (does modern IF even try to support this number?)

Looking at verbs.c it looks around 60 actions are supported +39 “simple” verbs for jokes(?), and looking at the file you reference it looks like there are 217 actual objects in the game.

You appear to have based your numbers off of the sizes of the arrays, despite the numbers corresponding not to words the parser knows but words in the sense of 16bit integers that the target computer processor liked to deal with. As per the comments in the source the arrays do not represent flat data, but contain sequences of words the parser should recognise (encoded as integer pairs representing up to 6 characters) followed by usage information. So for the verb array (which seems to be the most complicated) the eat action is associated with the words: EAT, CONSUM, GOBBLE, MUNCH, TASTE described as supporting 4 syntaxes and uses 15 numbers in the vvoc array (10 for the verb words and 5 describing the usage)

I’d be curious as to what the actual number of combinations are but I doubt it’s more than a few thousand.