Improv is a javascript library for procedurally generating text, designed primarily to be used in games and interactive fiction. It’s similar in function to Kate Compton’s Tracery; it generates text at random from a tree-like structure of “snippets” that can be composed together to form a template.

Improv, however, supports the use of a world model and filters that can dynamically change which phrases are considered for inclusion in the text, as it is being generated. This means Improv specs can be written to construct coherent text in relatively free-form ways, ensuring agreement with itself or with an external world model.

The HMS Reliable is a clipper commissioned 6 years ago.

Using a whale oil engine, she can reach speeds upwards of 32 knots. The Reliable is one of the new generation of vessels built to fight against the Arkodian fleet in the Short War. Her crew is known to be one of the more disciplined in the Navy. She is currently serving as a colonial troop transport.

The preceding text was procedurally generated by Improv’s hms.js demo. While the statements about the fictional ship are arranged in a largely random fashion, Improv ensures that they agree with a number of rules:

  • Only Navy ships have the prefix “HMS”
  • “Reliable” is a name reserved for clippers and other freighters
  • “Whale oil engines” only occur in newer ships
  • Only newer ships with engines are so fast
  • Only freighters are assigned as troop transports
  • Don’t repeat phrases
  • Try to mention different aspects of the ship with each phrase

All of those rules are expressed only through the dataset Improv uses to generate text; no actual code is involved in expressing them. This means Improv can deal with relatively complex realities without the need of elaborate logic.