Randomized Logic Puzzle

This roadblock killed my story for a couple months, since I’d just come off of some difficult code for the cards. Now I’m back working at it, but I still have no idea where to even start.

The concept is a Cluedo-ish themed logic puzzle. There’s been a murder, and the protagonist knows which weapon was used to do the deed, but not who did it or which of several guest rooms they’re staying in. The protagonist can ask around for clues as to who is or isn’t staying in what room or had access to which weapon, in your standard logic puzzle fashion of “Mrs. White’s a sloppy cook, there’s no way she’d be able to poison someone without leaving evidence all over the kitchen” (so Mrs. White definitely couldn’t have done it if the deed was done with poison) and “Miss Scarlet was visiting someone in the Green Room” (so Lady Scarlet definitely isn’t staying in the Green Room, or else the someone would’ve been visiting her, not the other way around) and “Colonel Mustard and Professor Plum both claim to have seen the wrench in the kitchen before it disappeared, and we know nobody else went in the room, so one of them must be lying and have taken it” and such. The goal is to figure out who has the murder weapon and which room they’re staying in so you can break in and snoop around for it. The protagonist can break into any number of guest rooms, and there’s no game over for any number of wrong guesses, so if you want, you can just brute force it by breaking into rooms until you guess the correct one, then go tell the inspector which room you found the murder weapon in, but the other guests get angry and the parser will make fun of you.

This is all pretty easy to figure out if there’s a single consistent answer, i.e. it’s always Mrs. Peacock with the revolver and she’s always staying in the Arboreal Room, so if you’ve played before you can just go straight there and bypass the puzzle completely. I can just hardcode a specific set of clues that works with that particular answer. It probably wouldn’t be too difficult to have three hardcoded answers, one of which is randomly selected to be correct, which would allow for some replayability, although there comes a point where you can identify the correct room because you recognize a hardcoded clue without having to solve the puzzle. If I can’t figure out how to randomize it, I might resort to that, but if possible I’d like to make it totally random, with clues like “[character1] and [character2] were meeting in [room]” where the computer makes sure that [room] is associated with one of [character1] or [character2] without knowing in advance which rooms are assigned to which characters or who exactly [character1] and [character2] are. Setting rooms and weapons to be randomly associated with specific characters is easy enough, but I have no idea how to dispense clues such that they’re accurate to a randomly assigned set of attributes.

1 Like

This is a hard problem! Designing a logic puzzle so that it’s both solvable and satisfyingly difficult is a problem of art. Automatically generating a set is possible, but the typical approach is to generate ten thousand and then write a tool that evaluates the difficulty and throws out the 9950 that suck.

I’d suggest a somewhat cheesy approach: design one good puzzle by hand, and then set up your game so that the characters/weapons/locations are assigned at random when the game starts. That is, you’ve got your clues written down:

C1 was seen in L4.
C2 never touched W3.
W2 was seen in either L1 or L2.

When the game begins, you randomly shuffle the character list “Plum, Peacock, Green, White…” and assign then to C1, C2, C3, C4… Same for items and weapons. This guarantees that you have a good puzzle with a random solution.

Then comes the hard part: you have to write code to narrate each clue in a way which doesn’t look completely robotic. This is a lot of work! Your example above of “Mrs. White’s a sloppy cook, so blah blah poison” only makes sense because Mrs. White is a cook and poison is a consumable.

I’d start by writing a completely generic version of each clue: “[Char] was seen in [location].” “[Char] has never been known to touch [weapon].” Then start writing more specific versions of each clue, hand-tuned to specific character-weapon-location combinations. Come up with an engine which selects the most specific text appropriate to a particular combination. (I7 rulebooks are good at this!)

This is a crap-ton of work – you need about a bazillion specific variations of each clue to make a satisfying experience. Maybe you don’t want to go there. But if you do, that’s the approach I’d use.


I did a very similar thing in Final Girl which was programmed in Storynexus which already has a card format. Mine was much simpler in that you had a cast of 8 characters who could be the killer. You could win the game by identifying the killer, but you had to choose from a list which you could only dwindle by finding suspects dead and crossing them off the list. Zarf basically detailed a method very similar, but I understand your frustration!

I thought of simulating this by not choosing an actual killer and leaving it to random chance based on the odds of how many characters were unaccounted for, but I did end up making it fair. I chose a killer at the start of the game, and added one more ‘dummy’ card to the deck so that there would be something to find in all 8 locations.

What helped was literally thinking of it as Cluedo - and literally having cards with all 8 potential victims in a deck, removing one (to the “envelope”) replacing it with a joker and then making the player draw from that deck as they unmasked victims. You might be able to work it out by physically simulating this–or at least thinking of it physically in your mind. If there are hints that eliminate suspects by implication, think of the player “drawing” these hints and keeping them in their hand - if the player has a hint, it can’t be in the envelope, and thus won’t be the solution.

Zarf mentioned rulebooks, but I would totally make tokens for each bit of information that you manipulate offstage and scatter about your map. The thing you can’t do is hint at what is in the envelope using this method - Clue is all process of elimination.

It might be a matter of "if it happened in the kitchen, the character mise-en-placed the murder implements, so you must discover who was not a chef to eliminate them. If the garden is the crime scene, you might find an epi-pen and need to discover who all is not allergic to bee venom…

…essentially you could pyramid the information so each location provides a specific set of clues to eliminate suspects. That makes for a lot of writing! Perhaps one set of clues like bee-venom could whittle the list down to three people who are allergic to bees, then a hair sample might also whittle it down to “it was a red-headed character” and that’s the info you need to decide between those three.


Sorry to keep adding, but the trick is figuring out which elements are random and gamifying those: IE - who has what color hair, or who may or may not be allergic to bees. Something like the bee allergy you could leave to random chance. During initialization if the crime scene is the garden, pick three characters who are allergic and then randomize the hair colors of those three so one matches the cross-referencing piece of evidence. Those are the elements which will change during play so the player has to work at it each time that scenario is drawn. What helps with this is leaving all the other unused elements in and random so there are red-herrings.