Skip to content

Posts tagged ‘Computer Generated Fiction’


I added a GUI and made some Progress

As you can see I started working on my GUI front end. I have not gotten around to learning the web front end side so its PYQT5 for now.  Some major hurtles That I got into, around, and then over this past two weeks or so was following up on my previous post. I ended up deleting a good portion of my code and then starting over. I refocused on serializing my data and then working up from there. There is also a plug in I am working on that ouputs my INI files to CSV.

Here you can see I implemented a unique ID called SUID which is unique to the scene file and to each scene. <UNIQUE FILE ID> S <SCENE NUMBER>

A unique scene_and_sequel group ID. <UNIQUE SCENE SEQUEL ID> S <GROUP NUMBER>

Also, each item in the pair is labeled as a scene or sequel.


The first and last pairs are removed from the working pairs. I am now going to start splitting them up and building out plots and subplots. You can also see the randomly generated emotional arc to be used later with the scene and sequels.



I added a bit of code really quick that splits up the working list into three parts of NON EQUAL values, because of course, any random number of working scenes may not be divisible by three.



Turning Generated Scenes into a Novel Format for Plotting

Here is where I am at:

Step 1.

Novel word count is divided into three parts. Each part is then divided into Novel Scenes using a randomly generated lengths specific to average novel Beginning, Middle, and End lengths. Due to this “fuzzy” math you will end up with a longer length novel then required.

Image one shows the input WORDCOUNT being divided into three parts, then each part converted into Scenes.

Image two is an example output of what the Scenes INI output file looks like. The file name indicates there were 105 Scenes created with a total of 101700 words. The original input was 100,000. The extra 1700 words were created by the fuzzy math during Scene generation however as you will see in the next step some of it will be lost.



Clip from a Scene INI file.

Step 2.

Creating Scenes and Squeals. Here is a good site on what they are. Did you read it? good. They did a good job. The original Scenes are divided into pairs and if there is an extra Scene, well, there is no longer an extra Scene.  Scenes and Squeals feed off of each other.Capture.PNG

Step 3.

The beginning pair and the end pair are special. They introduce the overall conflict and conclude the overall conflict. They are removed from the next steps.


Step 4.

The three act structure again. Due to so much data being moved around the three acts are recreated again as PAIRS, NOT including the beginning or ending pairs.


Step 5.

Beginning to Plot. In each act, a random pair is selected for a secondary Plot, or the Sub-Plot. I may potentially move to a four act structure and even add in a randomized function for how many pairs per act are given to the sub-plot.  Something along the lines of per N-thousands of words, 1+X number of possible pairs per act for the Sub-plot.

Step 6.

The final product. This particular case is entirely for example of course. As you can see in the INI file above, there would have been 52 pairs in that example. That is just to many for me to make in visio.



This is where I am at right now. I am always open to suggestions and comments.


Fuzzy Scene Generation and Choosing One of the Six Emotional Arcs

Today I worked on randomly generating one of the Six Emotional Arcs.  The class allows the user to specify one of course, but will generate one for you if you don’t supply it. This was simple to implement but I made sure to structure the code in a way that lets me go back and add weights to which Arc is selected and how future machine code will attach to it.


Now the fun part, the beginning of the Scene building process. I want to make sure that I can later import the files into Scrivener and Aeon Timeline 2, since I have both of those products. I will export and/or convert my INI files to CSV later on.

I scrounged around on the internet and I  came up with a starting formula for building the Scenes. The length of the fiction is divided into thirds, Beginning, Middle, and End. Each third of the fiction has two values High, and Low respectively. These are the minimum and maximum words in a scene in that third. The Middle and End sections of the fiction have smaller ranges than the beginning.


For each third, a scene is generated with a length of X until the third is full. There is also some fuzzy rounding going on in there to keep things different each iteration so I noticed that the scene word count is longer than the input word count. Here is a snip-it of a 10,000 word novel I generated. Each scene will eventually have all of the attributes in it such as its Characters, Location, Time, etc.


That’s all for now, have a good day.


Creating a bias towards character generation.


While working on my Fiction Generator and creating Characters I noticed that I was indeed getting a randomized type of character. This ended up not being realistic and so I started working on finding a way to make the randomized character be biased towards generic. Thanks to Brad and John for last nights conversation.

In the characters class I have a variable that has nine levels. I am using the Enneagram model however in the first instance the first nine levels are from Good to Evil and not personality types.  I wanted to create a bias towards the median when generating a random characters. This means that I will generate more moderate characters and fewer extreme characters.  I will later add a second Enneagram attribute for their personality type.

The levels and percentages are categorized as follows.
Heroic to Altruistic – levels 1 through 3
Average – levels 4 through 6
Thief to Villain – levels 7 through 9

1 – 2% Hero
2 – 3% Benevolent
3 – 10% Meritorious
4 – 20% Intellectual
5 – 30% Average Joe
6 – 20% Meat Head
7 – 10% Criminal
8 – 3% Tyrant
9 – 2% Villain

I ended up going with the following model because it allows me to easily adjust the percentages for each level individually. I generate a random int between 0 and 100 and compare it to the following stack:


Here is output from generating some random characters. Yes, there is also a bias set for gender generation that can be easily changed.


You will also notice that they each have random names. I used the existing names package and added a middle name function to it and I will also be adding other functions for webscraping names and adding them to the list. To-easy. Inside my class you can create characters with the same First, Middle, Last, or any combination of names. Here is an example.


That’s all for now folks. Keep on writing code.


Let the Programming Begin!

The exciting time of putting code to PyDev has officially begun. I gathered a few of my existing books together and then after an exhaustive search online decided on a few more to round out what I would need to help me. While I have years of programming experience, this project is meant to expand my Software Engineering capabilities to the absolute limit. I intend to teach myself Machine Learning, Natural Language Processing, and also Django.


I have gotten some great advice from the very few people that I have talked to about this project. One of the big pieces of advice that I feel that I should mention is one that I did not even think about before. One of the large untapped areas of reference for computer generated fiction is the role playing community. There are an entire community of people who have created interesting projects for creating procedurally generated dungeons, text based adventure maps, room descriptions, etc. While not being EXACTLY what I am looking for, they are ONE_OFF.

There are also other projects [ or select portions of projects ] created in other programming languages that I want to replicate in python. An exhaustive list of those to come later.

Another interesting thing is that this blog has shown up on a search engine and has begun to get traffic. I find that interesting and flattering. I might actually spend some time making wordpress look a little better if more people are interested. If YOU volunteer to make it look better, hey that’s more programming time for me.

I intend to use as much original code, if not entirely original code for the project. That’s the goal. Learn.

Another thing I have done is reach other to some writers and people who help other people write. I spend quite a bit of time thinking about thinking but I will often find myself needing an outside opinion of a different point of view or perspective on a problem to solve it. A compelling and unique solution to a computer generating fiction that a human can consume is the secret to success.

I have a theory. We, humans, don’t simply WRITE a story from beginning to end. We also don’t write them from word to word, sentence to sentence, or paragraph to paragraph. I have done some intermediate research on machine learning and natural language processing and from what I understand that is a condensed and simplified way of describing how they work.

However, we, Humans write a story in stages. For example the snowflake method. From one sentence to an entire Novel. I believe that using lots and lots of iteration, data analysis, and theory, I can incorporate backwards and forwards recursion to BUILD the data UP.

That’s all for now, if you have any questions or comments please feel free to get involved.



Curated Notes 

Procedural genererated polygonal planets. Procedural generated pologonal region terrain maps. Triangulated distances between primary objects, primary and secondary objects, tertersy and secondary objects, and so on. Distance from a ship around a planet is calculated by getting the distance to the planet, distance from the planet to the sun, distance from the sun to the next sun, the next sun to the next planet.

Novel backfill. Use a series of functions and objects to fill out an endpoint objective then after that work backwards in steps to reach that objective.  Work backwards at each step while building the novel backbone.

Pandas for data points? 

Start making scapy and beautifulsoup bots to get text novels and book descriptors, types of novels, character development traits, all sorts of things.

Pick a database backend.

Pick a web frontend.

Get a logo, just for the hell of it.

Establish the line between cowriter and author?


Generating Fiction and the Three Laws of Criss

*If you are reading this and continue to read on, then you will find that not only do I tend to ramble, but my thoughts are also all over the place. Well for that I say, sorry. If you are still reading these words just know that there were many, many more words that came before them and I chose to delete most of them for your sake.

The first Laws of Generating Fiction. The Three Laws of Criss.

Lets all take a moment to remember the greats of the past and acknowledge that sometimes inspiration comes from the most unwilling and unsuspecting of places. For instance, a young man in the military who would stray away and spend hours writing and would become one of the fathers of Science Fiction. While I did spend eleven years in the Navy, that man was not me. It was Asimov. I just couldn’t sleep and was thinking about thinking again.

Computer Generated Fiction and The Three Laws of Criss. ( we touched on the third law already. )

The First Law – The Universe and its attributes are immutable after creation.

The Second Law – They think therefor they must exist. 

The Third Law – For every character transformation there has to be an equal and opposite number of outside influences over an integer that is equal to time. 

What does this translate to in python ( my chosen programming language ) and how will this make my program completely different and revolutionary from every other program that is currently out there?

The First Law – The Universe and its attributes are immutable after creation.

Lets use a metaphor. In the original Star Wars episode 4, it opens up with…… “A long time ago in a galaxy far, far away….” Thus George spoke and a universe was created. A reference point was established. A big pointer that said, “you are here” that points backwards somewhere to “a long time ago”. *(somewhere to the left). You are in the present and behind you is a long time ago.

Thus, the great story teller you are you have just established a Universe and as a bonus a timeline as well. Good job. From now on, you can load the “Star Wars” universe whenever you want to edit it and you can move forward or backward in time and when you are done you can close the “Star Wars” universe.

Attributes and Immutability. This should be common sense but I will spell it out for you. In the beginning of your Universe you decided that Up was Up and Down was Down. You also Decided if Magic exists, if interstellar travel exists, ghosts can go “boo” and if zombies can or cannot run. They cannot by the way. If you are a programmer like me, then imagine that this is a Tuple. You don’t get to change it, you use it. I won’t insult your intelligence because if you are going to be programming your own machine to write a novel you should either be agreeing or disagreeing with me right now. If you have no idea what I’t talking about then we are two far apart for this conversation to have any real meaning and why are you here?

The Second Law – They think therefor they must exist. 

If a character is going to be used in any way, then that character MUST exist. That means that they must have a full beginning to end accountability of their actions with the Universe from the moment they enter the Universe and until the end of time or until they depart the Universe. This means setting a minimum standard level of attributes for each character.

The level of attributes can be deterministic, but there should be and will be at least a minimum for the program to run. Different levels of attributes and accountability can be set for primary, secondary, and tertiary characters. Much like a game, you set up the pieces and then let them play out and keep track of what happens, where and when. Only then can your computer truly keep track of the interactions of the characters within its Universe.

while universe:

for each timeline:

for each character:

for each interaction:


The Third Law – For every character transformation there has to be an equal and opposite number of outside influences over an integer that is equal to time. 

I covered this in detail already. Every conversation, action, event, everything, has attributes, and everything affects everything in some way either + or – or neutral. Everything is tracked and impacts the world around it, just like the real world.

Minor changes happen slowly over time. Major changes can happen suddenly. A person does not change suddenly from minor events and be believable. The data needs to be there to support that. I don’t want rehash the whole thing for those who read the last one. Still working out the math and formula there, but I think the idea is sound.



NaNoGenMo 2018 – Starting {awkward pause} now.

NaNoGenMo stands for National Novel Generation Month. Can you write code to produce a novel of 50,000+ words in the month of November? This is where the “Sort of” comes into play.

“The only rule is that you share at least one novel and also your source code at the end.”

Now, I may be violating the spirit of the November portion but as a single man with two kids and a full time job, I don’t much time to work on my pet projects. So, I will be entering in the 2018 competition and I look forward to spending an entire year making something that reflects that much attention.

Project Goals:

  1. Fufill the requirements of NanoGen.
  2. Provide a graphical user interface using pyqt.
  3. Create a co-writer application.
  4. Create Computer Generated Fiction that a reader will be unaware was generated by a computer program.