Read how I made a program generating fairy tales
Generating the plot
Studying the fairy tales of Brothers Grimm, I realized that a group of them worked after a similar structure.
You had one main hero, an evil opponent and a central conflict between them two. The story ends with a solution of the problem and sometimes also in a catastrophe.
I started to go trough stories to gather ideas for common conflicts.
In order to generate the rest of the plot I now searched for a way to include the solution of the central conflict. The graph below illustrates how the plots are generated.
In this example the evil opponent destroys something of the hero. Then the hero tricks him. In the end the hero kills the evil opponent.
Now I had the core part of the programm done. The programm now knew how to generate plots for fairy tales. The next step was to teach it how to turn this plot into sentences and add some unique details to it.
Telling the story
At first I created sentence structures the program could choose out of.
Some parts of the sentences are variable. They get a random word or wordgroup assigned out of a list. For example the destroy part is generated like this:
Now the programm could also have choosen other words out of the list, making it turn into this:
As you may have noticed, the hero and the evil opponent stay the same troughout the story.
The program decides at the beginning how to describe them both. Maybe the hero is a tiny mouse fighting an evil knight or the hero is a powerful mage fighting a strong barbarian.
With the sentence structures and the word lists added, the programm now knew how to narrate it's own fairy tales.
Try it Yourself