Infinite State Machine


Have you ever heard of a finite state machine (FSM)? It’s a term that gets thrown around when folks discuss mathematical models, digital circuits, or computer science. You’ll also see it occasionally in data networking (EIGRP uses the DUAL FSM to determine favorable routes.)

You might be wondering, “What is an FSM?” More likely, you may wonder, “Why is he telling us this?”

Perhaps it’s an oversimplification, but an FSM is basically a logical device used to compute results based on a set of conditions. They can be used to program computers to sort through a diverse array of data and arrive at pertinent conclusions or predictions. They’re called finite state machines because any given FSM can accept only the preset conditions it’s designed to consider, and those preset conditions can only be subjected to a limited number of state transitions.

I’m talking about it because people sometimes ask me questions like, “How do you come up with your plots? How do you keep character behavior consistent? How do you decide what the characters will do next? How do you keep it all straight?”

I like to tell them, “I use an infinite state machine.” Then I laugh when they look at me like I’m nuts. Despite all of the cool things I’ve done (the Rangers, bouncing, etc) I am – and I always have been – a total geek at heart. If someone wants to understand how I write, they need to understand the concept of FSMs, because I don’t believe that I decide what the characters do next. I don’t have to make an effort to keep their behavior consistent. I don’t decide what happens next. The infinite state machine does all of the work.

It goes back to the days when I game mastered pen and paper role-playing games like Advanced Dungeons & Dragons or Shadowrun. (I never really liked AD&D, but I mention it because people recognize it more than some of the obscure games I preferred.) A game master can run his game in one of two ways. He can script out the entire session and railroad players into doing what he wants so that it conforms to what he has planned, but this frustrates players because they don’t feel like they have any choice. Alternately, he can just sit back and let the players do what ever they want, but this puts a tremendous workload on the game master to improvise everything on the fly, and players often need some guidance to prevent them from being overwhelmed by the possibilities.

I used a hybrid approach. I planned a basic plotline of what I wanted to happen. I’d plan Plot Point A, B, C, and so on. I’d plan details for those specific points. I’d get the players started at Point A and then turn them loose. I’d let them do whatever they chose, and then play the session accordingly, even if it meant I had to shift the world around a little bit to make it all work out. I always thought, “They’re at Point A. They have to get to Point B eventually, but I have no idea of how they’re going to do that.”

Consider this example:
I start the game in a large city. The characters are walking back to their inn after watching a jousting tournament when they see a woman being attacked by three men. This is Point A and the start up of the infinite state machine. The players can help her or not. If they do help, there’s no guarantee that they can fight off the men. If they help her, and if they defeat the men, the woman will provide the plot hook that points them to Plot Point B. If they don’t help her, I have to come up with a new way to point them in the right direction. If they help but get their asses kicked, I have to decide if I’m going to let them get killed or if I’ll throw in some city guards to help them out. But what if they do save her, and she tells them to meet her in a tavern, but they decide to go to a brothel instead? Then I still have to come up with some way to make sure the story progresses.

The key here is to notice that I had no control over what the players did. I had the power to alter the world if I thought it would enhance the story, but I had no obligation to do so, and I could not change the details of the present moment without the players noticing. I could only affect the possible futures. Suppose the players decided to help the woman and were defeating her attackers more easily than I had anticipated. I could allow it to continue and let them enjoy their moment of badassery, or I could decide that tougher reinforcements were on the way, just to raise the tension. However, I could not make those specific attackers tougher in the middle of that specific fight without the players knowing I was messing with them. Assuming the players don’t kill them, I could allow the attackers to come back later, and be tougher at that time, but I couldn’t buff them up in the middle of the current fight.

From these gaming examples, we start to see the basic rules I use when I write:

  1. I know the characters get from Point A to Point B, but I don’t know how they do it, and I don’t know what condition they’ll be in once they arrive at Point B.
  2. I cannot control what the characters do or say. I only control how the world reacts to them.
  3. I cannot change the past or the present. Once it is written, it is done, but I can change the unwritten future.
  4. I cannot alter the outcome of an encounter to favor a character unless it is absolutely necessary to ensure the story continues.
  5. Any changes I make must be plausible and transparent to the reader.

(At this point I want to point out that rules are made to be broken, and these are no exception. I have broken them before and will do so again, but hopefully I’ve committed my transgressions with enough guile and skill that no one will see where I’ve cheated.)

I write stories like I mastered games, except my characters are my players. I know my characters’ personalities, strengths, weaknesses, fears, dreams, desires, education, and skills. I know the status of the world – everything from economy, politics, and weather to geography, gravity, and the limitations of magic. All of this knowledge comprises the starting conditions of my infinite state machine. I throw the characters into it, and they react in accordance with their natures. I’m not really a writer; I’m more like a man watching rats in a huge maze, and I just write down what I observe. I don’t always like what the rats do, and I sometimes wish they acted differently, but I can’t directly manipulate them without ruining the experiment. I can change the aspects of the maze and record what happens. That’s it.

Granted, the “rats” are my characters; the “maze” is my fictional world, and both are contained within my mind. Readers might think that I can do whatever I want, and I should be able to make the character do what I want, but that simply isn’t true.

Have you ever read a story where something improbable and nearly unbelievable happens just so the characters can survive or progress to the next plot point? It happens in fantasy fiction, usually through the use of magic, but it can also be found in contemporary fiction. The Davinci Code comes to mind. I lost track of how many times the plot progressed just because the main character had a flash of insight and figured out what to do next. Dan Brown might as well have written “Robert figured it out… just because.” I can forgive a single use of this, but I have a problem when it becomes a repetitive plot-driving device. What happens when you read that sort of thing? I don’t know about you, but I feel cheated. I want to call ol’ Dan and yell “Bullshit!”

Have you ever read a story where a character does or says something that seems contrary to your concept of them, but it has to be done or said in order for the story to continue? Does it confuse you? I know it confuses me, and again, I want to call the author and say “Get your shit straight!”

These jarring quirks in writing can be avoided if a writer follows my rules. Here’s one more example:

I have a character that’s between Plot Point A and Plot Point B. Point A was a remote lumberjack town where someone was supposed to know the identity of the assassin who’s tracking our hero. Point B is the confrontation with the assassin. I know that, when my character arrives at Point B, he’s probably going to get into a fight with the assassin. I know that the hero will need a sword and armor if he’s to have any chance of winning the fight.

However, I’ve let our hero run around inside my infinite state machine since he arrived at Point A, and now he’s gotten into more trouble that I anticipated. I didn’t plan for it to happen, but here he is, on the edge of a cliff, with the river below, and an angry pack of werewolves coming up from behind.

If I want the story to progress, he must survive. The river is his only chance. If I write that he jumps into the river in full plate armor and manages to swim to safety, any reader with an ounce of common sense will call me and yell “Bullshit!”

Therefore, he must lose the armor, and probably the sword too. So he takes it all off and jumps into the river, just in time to avoid the ravenous werewolf pack. I had originally envisioned the assassin would fight him in a large city, but I need to get the story back on track, so I decide the assassin will track him and the fight will happen after our hero pulls his water logged ass out of the river.

BUT, the hero has no weapon and no armor. I can’t make the assassin easier to fight because the readers have already seen him in action and know he’s a master in the arts of badassery.

At this point I look back through my notes to see what, if anything, I’ve previously established about this river and the surrounding area. I see that in an earlier dialogue it was mentioned that marauders prey on all traffic through this section of the river.

Therefore, it makes sense that our hero would be captured by them, because he’s unarmed and half-drowned. The marauders fish him out of the river, thinking they’ll ransom him or sell him to slavers. Our hero takes a day or two to regain his strength and to watch for an opportunity to escape. (This also gives the assassin time to find his trail and catch up.)

When the opportunity comes, our hero makes his move. Being a badass in his own right, he manages to defeat his two guards despite his disadvantages. This is plausible since the guards are just river rats with swords and armor. They aren’t trained soldiers or seasoned killers, and they aren’t watching our hero as closely as they would if they knew his identity.

This is another junction where it can’t be too obvious that I’m stepping in to save the hero. First of all, no matter how awesome he is, he’s fighting two armed and armored men at the same time, while he has no weapon or protection.

Chances are very slim that he’ll win without a scratch. Furthermore, chances are likewise slim that the weapons will be of the best quality or that his opponent’s armor will fit him perfectly. I could write that he kills his foes without getting hurt, the armor fits him like a second skin, and one of the river rats was carrying Excelsior (Excalibur’s brother.) If I do that, I’ll get more bullshit calls, and I’d deserve them, too.

When it’s all said and done, he has two swords. Both are poorly forged out of shoddy steel. Between the two marauders he managed to scrape together a full suit of armor that fits him well enough to protect him but his range of motion is restricted, and neither helmet fit him. Last of all, he has a slash on his right thigh, from his fight with the marauders. It isn’t deep, and it won’t pose a risk if he can get it cleaned and properly treated, but it definitely slows him down. Our hero doesn’t know it, but the assassin is close, and closing fast.

Now the stage is set for Plot Point B. Sure, it isn’t anything like I envisioned, and our hero is going to have a really tough fight when the assassin shows up, but at least it’s plausible that the good guy might win, and the reader’s suspense is even higher than it would have been had everything gone as I intended. Best of all, it doesn’t seem like I’ve stepped in to protect the hero, so I know the reader will be happy. As the author, I can look forward to more challenges since it now seems likely that our hero exit Point B in a totally different condition than expected, which will really make things interesting when I throw him into the infinite state machine to see how he gets from Point B to Point C.

When it’s all written, published, and on the book shelf, I’ll have one more choice to make. When someone asks me, “How do you think all of that stuff up? Did you have all of that planned from the beginning?” I can lie and say, “Why, yes. Yes, I planned it that way from the start, because I’m just that damn good.” Or I can try to explain the infinite state machine and laugh when they look at me as if they’ve just realized they’re in arms’ reach of an unrestrained mental patient.

3 thoughts on “Infinite State Machine”

  1. I think all successful fiction writers do some variation of what you describe here. You start out with a general idea of what is going to take place and then just run with it.

    People (and characters) are 110%  products of their environments. If you understand the composition of the person, you intuitively know how they would think and act in a given situation. The fun part, as a writer, is in not knowing what each step of the trip from A to B entails until you pen it. You know he has to get there but you seldom know what he will encounter in route. Or at least, I usually don’t.

    When these “targets of opportunity” appear, to develop the character or story as you move along, that’s where the good stuff is. No one knows how or why a character reacts in a certain way except the character. As the writer, you are more like a referee at a sporting event. You have no idea which play will be run beforehand, but you know all players must follow the set of rules of their nature and stay in-bounds on the field of their reality. If you allow them to play outside the rules or bounds, the crowds will boo you.

    I never know what a dialog will be in advance and usually not the day to day events that just pop up out of no where. The same passage written yesterday or tomorrow would, in all likelihood, be totally different than what the reader sees. Characters often go through the mood changes of the author in other words. lol Jim may have tried to reason with this asshole yesterday, but today he just kicks his with little or no provocation. It all just depends on what mood “Jim” is in the day he was written. If that makes sense at all.

  2. Totally off the topic of the post but this struck me:

    “People (and characters) are 110% products of their environments”

    the scientific side of my brain (ummm small yes) screams: error error error

    Anyway…carry on.

    (I am just here to read and hopefully learn how to better write these self help books I am currently working on ….. lmtlsao I may have to find a ghost writer.)

    1. I have never tried to write a self-help book. After thinking about it, I think, if I were to write one, the first sentence would read, “If you had to ask for assistance to find the self-help section, this book probably isn’t going to help you much.” ;-)

      Ok, back on topic – I never thought about this before, but the whole “nature vs nurture” argument concerning human behavior doesn’t really apply to fictional characters, since their genetics is entirely up to the whim of the author. In fact, their genetics is just another aspect of the story environment, so it is as you say; the characters truly are totally defined by their environment.

Comments are closed.