Decisions, Adventures, and Trees

Choose-your-own adventure stories brought to code

Nolan Kovacik
4 min readDec 12, 2019

What is a “Choose your own Adventure” Story?

A choose your own adventure book is a classic children’s storybook format that became popularized in the 1970’s. The Netflix special, Bandersnatch, re-popularized the idea of choose-your-own adventure stories. Ironically, these stories often had very dark themes, but we won’t get into that right now.

Choose your own adventure stories—ironically—often have very dark themes.

Essentially, these stories presented the reader with a choice, and told them to skip to a certain page to continue on the path they chose. This actually can be modeled using a “Decision Tree”!

What is a “Decision Tree”?

Decision Tree: These show potential splitting paths from a particular point, and can be graphically represented.

A tree is a type of data structure. Woah! Don’t let that scare you. A tree is actually somewhat intuitive to read, and you have likely read dozens of them in diagram-form already without realizing!

When you imagine a tree, you need to understand its contents. Its contents read in-order, or chronologically. In the image above, it reads left-to-right. When you read a tree diagram, your eyes naturally check out each circle-item one at-a-time. That’s intuitive; you are reading correctly!

Each circle-item is called a node. A node’s most important quality is its content-data. In the case of a choose-your-own adventure story, the content-data is the story itself.

A node also holds information about its next possible nodes, which are often referred to as children or neighbors. A connection like this is forged through a splitting choice in a choose-your-own adventure story.

What a Decision Tree can’t do

A node within a tree holds information about what is next, but it never references what came before. Much like time, once you do something, you can’t go back.

Awesome! Now you know all the basics about trees…but wait. Let me blow you mind! Choose-your-own adventure stories often break this rule. Check out this diagram below:

Decision Graph: Sometimes, games and stories with choices can buckle back to earlier states.

This diagram is breaking one additional rule about trees: a node can only have one parent ever. The dotted lines show that there both buckling back, and an additional parent to some of these nodes.

This represents a continuation in a story that makes you repeat previous content. For example, a story might introduce time-traveling, and let you rewind after a terrible disaster occurs. In this case, you are put back at an earlier state.

Graphs to the Rescue

A graph is a more generic term for a tree that breaks many rules. Anything goes in a graph, and that includes things like buckling back.

In a tree, there is a strict chronological structure that cannot be broken. A graph does not have that; in fact, you can often start anywhere and end up anywhere. They are like a tree if you drew extra lines randomly between different nodes.

The “Fault” of Tree-Structured Stories

Choose-your-own adventure stories have one main issue: the creator must put in all the hard work for creating every outcome possible, but the reader might only see a small portion of that content.

Typically, a user who experiences the adventure just once would only see log(n) of the final product, where n is the number of split decisions possible. For example, if you had 10 split decisions, the reader might experience anywhere from 10%–20% of the full story (depending on how many choices each split had). I got this number by calculating log(n) ÷ n, which represents the percentage of the content that an average user consumes.

This is a function of a trees “height”, which is the number of steps it usually takes to get from the starting node to one of the ending nodes. The height is equal to log(n), although for some of your math-savvy folks out there, it might be log-base-10, log-base-2, or even log-base-k, where k is the number of split choices possible.

Building an App

I created an app that models decision trees, and in fact lets you create your own decision tree via Command Line Interface! I did this by modeling two main class objects:

  • The “Book Cover” object that contained information like the title, synopsis, and referenced the first page.
  • The “Event” object that contained textual information, an array of choices, and an array of outcomes that those choices lead to. An outcome was literally a subordinate event.

After doing all of this, I created a markdown-writer class that generated results once the main function was completed. You can check it out at my GitHub Repository here: https://github.com/noltron000/adventure

--

--