Adventure Games and Interactive Fiction

Experimenting with Procedurally Generated Mysteries

by Gamefic on February 28, 2021

One of my long-term pet projects has been procedurally generated content for mystery games, where the mystery's suspects, clues, and solution are all dynamic. My most recent experiment is a short text game called AKA: Sammy the Blade. The game's objective is to identify a fugitive among the guests at a hotel. The mystery, at its core, is a logic puzzle.

The mystery generation works by creating suspects with randomly selected attributes, flagging one of them as the fugitive, and creating a set of facts that can be used to identify the fugitive through deductive reasoning. (In logic parlance, these facts are often called premises.) From there, the game uses the facts to create story elements (physical evidence, witness testimony, etc.) that the player can discover through exploration. The player can access "notes" where each fact gets logged when a game event discloses it.

I did my best to guarantee that the mystery is always solvable. To that end, I wrote a separate puzzle generation library. It takes an array of subjects with a finite set of attributes and generates a list of premises that can be used to deduce the answer to a question. Here's a simple example of a randomly generated puzzle:

The animals are the dog, the cat, the pig
One of each is red, green, blue
One of each is small, medium, large
Which animal is red?
Known facts:
* The cat is medium
* The pig is small
* The large animal is not red
* The small animal is blue

In this example, the red animal is the cat.

My ultimate goal was to make it mathematically provable that the generated puzzle always has a discoverable solution. That said, when it comes to advanced mathematics, I'm a layperson at best. It's totally possible that my proof of solvability is flawed.

The suspects in AKA: Sammy the Blade have three attributes: hair color, eye color, and room number. One of the generated premises could be "The guest in room 1B has green eyes." The corresponding story element could be a guest who, when questioned by the player, happens to have noticed his neighbor's eye color.

The game's content works within fairly rigid parameters. It's always set in the same hotel and populated with a handful of the same characters (the manager, the security guard, etc.). The hotel always has six randomly generated guests. Only three of the guests are viable suspects based on what the player knows of Sammy's itinerary. Everything else is generated from the logic puzzle's premises.

There's a lot more I'd like to do with this concept. One of my next experiments will be to see how well it scales with more suspects, more attributes, and more variety in the generated story elements.