Finite State Machines

Simplified Modeling for Event-Driven Systems

Finite State Machines are one of the most frequently used State patterns for games because they are one of the most simple ways to represent and implement logic for event-driven systems. A Finite State Machine is model of a dynamic, event-driven system. FSM's allow for simplification of the logic of complex event-driven systems. The simplification comes from the structure of the FSM which is specified below. Finite State Machine model specifies that the event-driven-system can be represented by:

  • a finite set of states - represented by nodes

  • a finite set of events that cause the system to change state

  • a well-defined set of state-event transitions (event-arrows)

  • memory to keep track of the current state of the system

  • identification of the starting state

  • at any point in time, the system must be in one, and only one state of the system.

The benefit of using an FSM to model a system is that once a system has been represented using a FSM format, then it is straightforward to write code to implement logic of the system.

An FSM is often represented as a diagram with nodes to represent each state and arrows between nodes to represent valid transition events. A table can also be used to represent the same logic.

Finite State Machines

The image below shows a Finite State Machine diagram for managing Event-Driven changes in GameState which correspond to Level-Change Events for the MiniGame used in Project 3.

Throughout this course we will look at the fundamental computing structures associated with games and stories. The online book listed below "Game Programming Patterns" is a resource we'll use throughout the course.

In computer science, programming patterns are an important way to understand and communicate about common abstractions.

The State Pattern defines the behavior of a dynamic object.

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

As discussed in the book shown below, a useful way to think about games is to consider that they can be represented as a hierarchy of "looping systems."

In Computer Science, such looping systems are called State Machines.

Last updated