Gamefic

Adventure Games and Interactive Fiction

Using a Dictionary Database to Build a Smarter Parser

by Gamefic on December 10, 2014

One major challenge in parser-based adventure games is avoiding guess-the-word problems. Players can get frustrated when they attempt to push, activate, or turn on a button, only to discover that the game expected them to press it. Developers typically have to rely on extensive testing and their own meticulousness to make the parser as comprehensive as possible. Right now I'm experimenting with a more automated solution: querying a dictionary database for synonyms of implemented verbs. The game can use this data to make sensible recommendations for unrecognized commands.

Here's how it might look in-game:

> travel north
I don't recognize "travel" as a command. You might be able to use "go" instead.

> inspect chemical
I don't recognize "inspect" as a command. You might be able to use "examine" or "analyze" instead.

> blaze wood
I don't recognize "blaze" as a command. You might be able to use one of these instead: burn, light, or ignite.

In order to make this work, I wanted to add a step to the build process that would find synonyms for implemented commands and automatically generate the recommendations.

The first step was to find a digital thesaurus. Princeton's WordNet database looked promising. Not only does it provide definitions and lexical usage, it groups words into sets of cognitive synonyms called synsets. With WordNet, I could query a word for its verb definitions and get a list of all the words in the same group. Sounds perfect. I downloaded a SQLite version and looked at some query examples.

Next I wrote a script to collect synonyms for common verbs. It gave me 57 synonyms for the word go. Depart, move, run, and travel are a few that fit how go is used as a game command. Blend, croak, function, and kick the bucket, not so much. The database has 30 different definitions for go, but only about 4 of them are applicable here.

I don't see any way to automate the selection of applicable definitions, so this feature is still going to require a little user intervention. Here's how I imagine the process:

  1. The SDK collects a list of definitions for each command.
  2. The developer selects which definitions to use.
  3. The build process generates recommendations for synonyms based on the selected definitions.

Okay, so it won't be the zero-intervention plug-and-play feature I had hoped it would be. Still, with a little configuration, it should be an easy way to fill some of the parser's gaps. Developers could also use this tool to discover new verbs that merit their own implementations.

I'm currently looking at ways to integrate this feature into the Gamefic IDE I'm building in Eclipse. One concern: the SQLite version of WordNet is 436 megabytes. I'm not sure I want to add that much weight to the application. Two possible solutions are to make this feature optional, or to provide an online service that the IDE can use instead of a local database. Maybe even allow for both.

Sometime in the next couple weeks I'll build a demo game to see how well this feature works in practice.