Blog‎ > ‎

Procedural Stories

posted Jul 29, 2013, 10:06 PM by Skyler Kistler   [ updated Jul 30, 2013, 8:28 AM ]
I haven't posted here in a while so this post may seem a bit out of context. I've kept my most current project a bit on the down low. To save yourself the suspense I'll come right out and say it: game generator. Woo! :D More info later. 
For now, I would like to write about the procedural story generator I've just designed.

As a note of warning, I haven't really looked into this field. I really don't know how much has been done in this area, and I haven't read anything about it. So if some of my ideas are similar to things that have been done, I'm sorry for not crediting whoever's come to these ideas before me.
That being said, please do use any ideas you may get after reading this. Please do send me your implementation, I'd love to see your work ^_^

Firstly, I've always thought of game narratives as trees. In a traditional novel, you're led down a certain path, the details are handed to you as you go along. You may deviate from the set plot a little bit, maybe go on tangent stories, but you're always progressing. I visualize them like this:
straight story
These are fairly easy to generate. User input is never a problem, all you'd have to do is generate an 'outline' then fill it in with pre-written text or something. Bleh. Who cares, novels are a dying medium anyway.

But with games, particularly large RPG's like The Elder Scrolls, plot points are given as you go. There are side quests everywhere that branch off this tree, having brief conversations with NPC's adds little leaves to the branches that fill in even more details. Those stories look something more like this.
big ass tree

These present much more of a challenge to generate, let alone as the player progresses. I'm sure people would be more dazzled by a program that knows the current trends in society and the English language, and can write completely unique stories start to finish, but quite honestly that's not practical. It's not practical on modern hardware, and it's not practical until we can emulate the human mind and how it evolves as it conforms to society. That's a different post.

What we can do though, is write the leaves, and generate the branches.

The system I've designed generates branches off of human-provided leaves.
To start, I had to break up what defines a general story. There are multiple ways to do this, this is just the way I think will work for me. 
On the upper tier you have four categories. Beginning action, rising action, climax, and the falling action. Most people who've taken a basic literature course are familiar with this. You start with a beginning seed, a kick starting scenario. You move on up the tree, providing details that add to the story. This is done by taking from pre-written tidbits with variable blanks. What I mean by that is there are universal variables used throughout the story that are generated with run of the mill name generators. For example:
%PROTAGONIST% then went from %SETTING_1% to %SETTING_2%
PROTAGONIST would be the name of the protagonist, SETTING_1 and SETTING_2 would be generated.
Tidbits would be organized primarily into which part of the story they fit into. If it's part of the beginning of the story, it would be organized as such. 

The old computational creativity problem still stands though. How do you keep random from being just noise? How do you keep everything in context? Johnny can't be in a story about dragons one moment and suddenly be trying to get a girlfriend in his 1950's high school. 

My solution to this is quite straight forward and not a great solution by any means, but it will work and that's all that counts for now. My solution is to have context tags with each tidbit. When choosing tidbits, context 'clouds' will be referenced. These could be learned by some sort of AI, but my implementation is just going to be static. 
The romance cloud will contain things like "heart, love, passion" etc.
Similar to the YouTube search looking at the tags of a video and relating them to the search term, the generator will look for tidbits with matching contexts. 
I could go into deep detail how I plan on doing this but the only people who would care are coders, and they can either guess or read my future implementations.

From there, branches are created as the player progresses. If a player spends more time interacting with NPC's about "heroic" contexts, then "romances" contexts will fall out of favor when generating. The generator will favor tidbits that reference variables in use. For example, if a tidbit has %SETTING_3% but setting 3 hasn't been defined yet, that tidbit is much less likely to be chosen.

TL;DR: Game stories are trees, the player is climbing this tree as it grows, leaves are chosen to populate the branches according to past choices made by the player.

My first implementation of this general idea will be very straight forward, a linear approach built into the basic mini-game generator I'm working on right now. Maybe one day I'll make a full fledged RPG generator though that will use this idea in full.

Sorry for the long read, I hope you find it as interesting as I do :)
Most of my inspiration comes from Michael Cook (@mtrc) and his work on Angelina.

More info on the game generator soon!

To be more literal, the only human written parts would be dialogue, and keeping the game contextual would come with much perfected human code. The backbone as to what characters are going to say is generated by the code, taking into account what the player has been interested in so far. 
I think it would be interesting to have an RPG start with one static scenario for all players (like losing a loved one or being whisked off to jail) and then depending on how the player reacts is how the game evolves. I think this will be my next project.

Thanks so much to Christer Kaitila (@McFunkypants) for sharing this, you're awesome ^_^