Randomized variation

Something that’s come up on several of my projects recently is the question of how much randomized text variation can add to the sense of depth in a scene.

In particular, how good a job does it do of simulating lots of different, hand-crafted pieces of content? Are there better and worse ways to deploy random content for this purpose? Do you have a generic sentence form with a lot of randomly swappable elements, like

A red/brown/black/grey dog/fox/squirrel scampers/runs/hurries past you into the undergrowth. ?

Or a table with a lot of hand-rolled sentences, each unique, but each going to be the same every time it appears? Or some variation on all these?

For interactive fiction, this tends to come up a lot in cases where we want to make the world feel deeper and more fleshed out. We want a player to be able to browse a bookshelf and find the titles of many many books. Or hang out in an outdoor area and see lots of environmental messages suggesting people going by, animals passing through, etc. Sometimes it’s possible to rig up a full simulation for this kind of thing — that is, actually track dozens of animal objects running through the gameworld — but usually that’s a lot of overhead for a lightweight effect. (And see Matt Wigdahl’s comments on the “foley” system in Aotearoa.)

My current operating theory is:

1) it’s good to have a mix of more generic sentences with lots of variation and more hand-crafted sentences with moderate variation. This keeps things from feeling too predictable.

2) where random variation is used, the most productive way to use it to maximize the *impression* of content is to construct pairings/arrangements of random elements that are themselves striking and memorable or distinctive.

I brought this up on the #craft channel on ifMUD, where I had the following conversation with Andrew Plotkin (“zarf”) and Dan Shiovitz (“inky”). They had a couple extra points I hadn’t come up with, so, with permission, here’s what they said:

Emily says, “so I’ve been thinking about randomized output and zarf’s observation that having random text composed of (say) N variants * M variants does not produce the sensation of N * M different things”
Emily says, “but something more like N + M maybe”
Emily says, “(I may be misremembering, but I think this came up years ago re. Hunter in Darkness)”

zarf says, “Probably”

Emily says, “but what I am wondering is, does that still hold true if the combination of N and M is itself surprising/memorable? I’m thinking of the Curses radio here”

zarf says, “it’s never *exactly* true”
zarf says, “and you can finesse it in various ways”

Emily says, “where if you actually imagine an easy listening version of Head Like a Hole, that is a specific thing”

zarf says, “that’s a good example except that I can’t imagine an easy listening version of Head Like a Hole”

Emily asks, “The Real Slim Shady on Glockenspiel?”

zarf says, “having grammatical variations is more memorable than word variations, for example”

Emily says (to zarf), “hm, yeah”

zarf says, “so allowing both ‘The Real Slim Shady on Glockenspiel’ and ‘a Glockenspiel rendition of The Real Slim Shady’ is more than twice as good”

Emily says (to zarf), “that is an excellent point”

inky says, “anyway, it seems to me like the goal probably shouldn’t be to create something that is entertaining enough to act as “primary content””

zarf says, “right”

Emily says (to inky), “well, no — I’m more thinking of things that can be used as dynamic window dressing”

inky says, “but rather have it be secondary content that occasionally produces something interesting enough to act as primary content”

zarf says, “(this reminds me that I should write a blog entry about that MMO prototype that I never did anything with)”
zarf says, “the secret plan that I never did anything with was to combine the window dressing with a power law of frequency, so that the room descriptions are random but one *particular* random room is your home base and you see it more often”

Emily says, “huh”
Emily says, “that’s interesting”

zarf says, “and then there are the rooms you visit frequently, and the rooms you visit rarely”

Emily says, “what I did with CoS for things like the pedestrians was to have a lot of autogenerated stuff and then layers of handcrafted more-specific stuff”
Emily says, “in an attempt to reproduce that feeling where you see a lot of mundane things but occasionally something surprising”

zarf says, “yeah”
zarf says, “I like the idea of making the handcrafted stuff *still* somewhat random, just rarer”

Emily says, “from a narrative point of view, I guess the purpose of this is to suggest to the player over time what is normal and what is slightly exceptional in this environment”

inky says, “or to surprise or amuse or disconcert them”
inky says, “(which are all based on defining normal and then violating it, so)”

18 thoughts on “Randomized variation”

  1. There’s a surprisingly powerful rule of thumb here: read the source of your random matrix. If you’re excited to see what it will do, then it will probably generate exciting content. If it sounds banal, it probably is.

    To pick on your example, “A red/brown/black/grey dog/fox/squirrel scampers/runs/hurries past you into the undergrowth” sounds pretty boring. You kind of already know what it will do.

    Whereas a list of pop musical hits combined with a list of a dozen obscure musical instruments is likely to at least come up with something humorous, like “The Real Slim Shady on Glockenspiel.”

    BTW, IMO, true randomization is rarely the right thing. Instead, I prefer pseudo-randomized content, with a constant hard-coded “seed” which generates random-like output.

    With true randomness, rare events will sometimes come too early, confusing the player’s experience of the setting. If the very first raven you see is white, you won’t know whether that’s rare in the setting, or whether that’s just how the setting works.

    With pseudo-randomness, you can have a repeatable procedurally generated experience; if it generates an undesirable outcome, you can reproduce and fix the bug.

    At a minimum, shuffle your variations, don’t just select them randomly, or you’ll get some ugly repetitions.

  2. To pick on your example, “A red/brown/black/grey dog/fox/squirrel scampers/runs/hurries past you into the undergrowth” sounds pretty boring. You kind of already know what it will do.

    Whereas a list of pop musical hits combined with a list of a dozen obscure musical instruments is likely to at least come up with something humorous, like “The Real Slim Shady on Glockenspiel.”

    Which was kind of my point, yeah — you want the elements you choose to randomize to be things that will play off each other to create results memorable in themselves. (And yes, Inform’s pick-at-random, at least, is guaranteed not to pick the same thing twice in a row. “Don’t show anything rare immediately” is a slightly subtler point that would take more work to code.)

  3. A random observation (one I made when we got together in London, iirc).

    Random such as “the tall/small/fat/thin man/woman asks you if you like cheese/talcum powder” is rarely any use, IMHO. And standout better solutions aren’t that much more difficult to code.

    Since the seventies in ‘proper’ natural language generation AI, we’ve used generative grammars, a la Chomsky.

    s -> “[interesting character] asks you if you like [useless item]”.
    interesting-character -> “A Buddhist monk”
    interesting-character -> “A [person-adjective] [person-type]”
    interesting-character -> “[friend-short-name]”
    [person-adjective] -> “short”
    [person-adjective] -> “tall”
    [person-adjective] -> “fat”
    [person-type] -> “man”
    [person-type] -> “mime”
    [person-type] -> “aspidistra”
    etc…

    You can then add various kinds of tags to the rules so you pick suitable ones for your current game state, and so choices at one part can affect choices at another (choosing ’12 year old girl’ as the subject should prevent you from choosing ‘her 14 children’ as her travelling companions).

    Then the next stage is to add planning: use simple tests to check the quality of the final output. Stuff like checking for alliteration, for frequency of previous use, for distinctiveness of character description, etc. If the final output fails the test, the code goes back and tries again.

    This approach is about 30 years old now, and does really nicely on constrained text-generation tasks (the kind we’re talking about), and gives far more organic variation than madlibs style replacement.

    The best book on how to build stories out of this kind of stuff is “Scripts, Plans Goals and Understanding” by Shank and Abelson. Though interestingly it is written from the NLP rather than generation perspective.

    I’ve used this for a couple of projects. I do have a bunch of code somewhere to do a simpler version (tagging and frequency rules, but no planning), in Python, if it would be useful.

    1. All good points. I didn’t delve too much into this kind of thing in the original blog post because I was sort of more in the headspace of “what do we pick to go into those slots? what should we randomize at all?”. But I’ve used similar techniques on various projects, short of the planning stage. (City of Secrets has randomizers to plug in information about different types of pedestrian, e.g., and Savoir-Faire generates variable sentences using a combination of frequency and a style tracker — so if it was long-winded last time, it will pick something shorter this time, and so on.)

      Assembling a whole sentence and checking it for quality is something I haven’t played with much, though, and that is definitely a promising approach.

      And thanks for the book recommendation.

  4. [missed the point there – the point is that with a generative grammar you can

    a. Use it to generate larger scale things, not just text.

    b. Totally override what it is doing at any level of detail.

    c. Have a big go away rulebase, and then target a tiny subset of it easily in the game (i.e. pick just ‘useless-item’ to generate, rather than a whole sentence).
    ]

  5. Here’s a design problem, rarity vs. frequency:

    Say we have a street view with lots going on: a flow of pedestrians and vehicles. We want to, at the same time, ‘numb’ the player’s senses (present all this as mundane and insignificant window dressing) and, perhaps, every now and then give her little sumthing sumthing to surprise or entertain her.

    Suppose we’ve managed to prevent those rare things from appearing too early, so that the player knows what’s rare in that setting. (So it entertains.) But what if the randomization starts to produce some pattern that the player notices? (this is the player is always paranoid rule)

    For ex. what if the player happens to see a red animal run past every time/many of the times she goes north. Now the player starts to think there’s something to the red animals, that red is significant. Or that travelling north is the way to proceed. Maybe the red animals will lead her somewhere, maybe north. Then she starts to pay attention to the colour red, and every turn she does something that ’causes’ the red to appear she thinks she did something right or something dangerous.

    The problem is that playing IF is always in some respects like reading a detective novel: all details are potentially important. When you walk on the street in real life you see passers-by all the time and don’t pay any attention to them. But if you read a novel and the description of the street specifically says there is a lady in pink, two men in grey and yellow bus there, you start to wonder why those are mentioned. You think you have to ponder there motives or reason to be there, or at least remember them for later reference.

    1. The problem is that playing IF is always in some respects like reading a detective novel… if you read a novel and the description of the street specifically says there is a lady in pink, two men in grey and yellow bus there, you start to wonder why those are mentioned.

      That’s true, though I think the problem isn’t quite as severe as you suggest. Typically if something like that is happening every few turns, it’s a brief sentence or two long, and it doesn’t seem to have a direct bearing on any of the puzzles, I’m inclined to assume it’s just background. It becomes most problematic in a game where it’s easy to get stuck and the rules by which the world works are not very well defined.

      With a more fluid screen model, I suppose you could even do more to signal that these elements weren’t important — for instance, having the atmospheric text show in grey, and perhaps fade from the screen after you made the next move, indicating that it’s not an important part of the story — so that as you read back over the transcript what you would see was the important stuff.

      Could be interesting, anyway.

      1. I agree, most of the time these messages are easy to interpret as atmospheric. The problem might arise when the player doesn’t know what to do next (especially if the goal is unclear) and starts to grasp anything for clues – then the atmosphere takes over the game, so to speak, from the player’s point of view at least. It’s sometimes difficult as an author to notice when there’s a risk of this happening.

        Screen effects for atmospheric text, that would be fun to see, indeed. I wonder: would one, after playing some time, start to ignore that background text and read only ‘the important stuff”?

      2. An even kinkier idea for changing the scrollback: descriptions initially have a lot of detail but not a lot of atmosphere to them. After a few moves, they retroactively change to reflect which items the player actually chose to interact with, and how. So the gun only stays mentioned if it gets fired later on. Otherwise, that descriptive text withers and vanishes… so the foreshadowing is retroactively removed.

        You’d have to give people a reason to keep going back over the original story, though; most people don’t read scrollback obsessively enough to make this an interesting effect. buuut… maybe with something like Undum it would make sense. Undum does that kind of text fade-out stuff anyway.

        Hmmm.

      3. What a great idea to have an unreliable scrollback.

        Other than it might be a chore to keep tabs on what’s changing.

        Undum wouldn’t make it very easy to manage. The fading effect is just a little bit of javascript.

      4. I think you’d really have to present it in such a way that the player thought of creating the transcript/scrollback as a primary goal, rather than just a trace of his movement through the world. Maybe something close to The Space Under the Window; or a situation where you’re trying to concoct an alibi or personal history… but you’d need the scrollback not to be too long. It would presumably also edit out any missteps the player made (something some authors have argued for anyway) and repeated look and inventory commands.

      5. As a player I’d be disturbed by an unreliable scrollback. (I’ll store that thought away for future use: if the interpreter hacking could be made to work it could be a subtle but effective way to undermine the PC’s apparent hold on reality.)

        Personally I don’t often check the scrollback because I expect commands to produce repeatable output. Rather than trawl back through pages of my floundering, I EXAMINE or LOOK again at relevant objects. Having the results of those commands progressively shed the atmospheric detail so that only the plot-relevant words remain could make a really natural way to guide the player to their goal.

        Now that games tend to play in verbose mode you could even have the room-entering description pare down to the “noticeable” features while an explicit LOOK causes the PC to describe “everything” afresh. I’m imagining an IF reflection of the way that we usually glance at things we’ve previously seen but can still focus if we need to.

        If this effect has been implemented before I haven’t noticed it (although if it’s done well maybe the player shouldn’t). It was just something that this thread set my brain to worrying at.

  6. The key is to make randomized content not to look like randomized. I barely pay attention to several pedestrian that arrive, do something and leave in the same turn, so if one of these pedestrians do anything memorable or important to the story it is likely to be overlooked by the player. Same for handcrafted text or grammatical variations, in this context.
    The use of purely randomized text would be useful in an “incremental messaging” like trying several times to break a door or similar. Those messages can make the player feel like the parser “understands” what he is trying, even when it is a “You can’t do it” type response.
    The best way, IMHO, to achieve a certain sense of varying environment, conciling with the idea of memorable or important events is to actually have the thing happen. Why is a red fox passing by me in the undergrowth?. Perhaps it is just looking for food. Perhaps it is returning to it’s den, following a way that drives through an unknown location we could take advantage with in the resolution of a puzzle…

  7. I think one way to make the (N,M) random options look more like N*M than N+M is to have them occasionally interact. For example, with Chomsky grammars, this could be achieved by having nonterminals occasionally interact (a context-sensitive grammar). I believe Sims 3 used this kind of grammar.

    In your example, the adjective (all colors), noun (all critters) and verb (all synonyms for running) are quite obviously independent, and this contributes to the player’s perception of additive randomness (the total information content of two independent random variables is additive). But if the random words occasionally interact – e.g. whenever a black animal hurries (as opposed to scampering), it is accompanied by an ominous clap of thunder and a streak of lightning – then the variables are no longer random, the information content is a bit more than the sum of the parts, and more importantly, there is an enhanced perception that the randomness still holds some surprises (at least I think that perception is enhanced).

    I agree with Mastodon and Dan that making randomness look non-random (e.g. by using a random seed that subtly depends on game variables) is another way to hold the player’s curiosity.

  8. as a postscript to what I wrote above, I think that writers often worry about accidental interactions/clashes between their random words, and this results in just the kind of bland “the ADJECTIVE NOUN walks past and VERBS” sentences that you’re abhorring, where every word is compatible with every other word, and the result is boring. My hunch is that it would be better to deal with the clashes/interactions explicitly, rather than deliberately choosing options that never clash (these are sooooo easy to spot)

  9. We did a lot of this in King of Dragon Pass. It’s full of code like

    text: The told us about the vicious nomads of the eastern land of Prax, who rode .

    to allow for repeatability. This particular example has different bits of information, though more often it was variation to avoid looking obviously repetitive (like your random animal example).

    This particular example was also designed to be inside a larger randomization — sometimes you’d get entirely different information.

    Of course, KoDP doesn’t fit into the normal IF model, but it’s certainly interactive storytelling.

  10. Oh ^#*@! That got eaten as HTML. Let’s try that again:

    text: the vicious nomads of the eastern land of Prax, who rode «d4:large-headed, stocky cows/horned deer/long-necked birds/dogs».

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s