What Makes Things Happen

State

A player enters the room. She studies the board, contemplates, then reaches out and moves her pawn from e2 to e4.

Now something has happened.

The board's state has changed. Before, the pawn stood on e2. After, it stands on e4. Before, e2 was occupied. After, e2 is empty.

Events

What caused this change? Not time itself---we saw that time passing alone changes nothing. The board sat for a year and remained the same.

The cause was an event---a discrete occurrence, a moment of action.

Natural LanguageNotation
A player moved a pawnevent: move pawn e2 to e4
Something happenedevent: (action, details)

Events are the punctuation marks of change. Between events, the state is frozen. When an event occurs, the state may transform.

The Discrete Nature of Change

In chess, change happens in discrete steps. There is no "halfway" between e2 and e4. The pawn does not smoothly glide across the board. One moment it is on e2; the next moment (after the event) it is on e4.

This discreteness is fundamental. We do not ask "where is the pawn at time 3.7 seconds?" We ask "what is the state after move 1?"

state_0: initial position (pawn on e2)
event_1: white moves pawn e2 to e4
state_1: pawn now on e4

Time, for our purposes, is measured not in seconds but in events.

Events vs. Time

Some systems do care about continuous time. A physics simulation tracks the position of objects at every instant. A video game runs a "game loop" that updates sixty times per second whether or not anything meaningful happens.

But many systems---perhaps most---are like chess. They wait.

Natural LanguageNotation
Time-driven: something happens every tickloop: update every 16ms
Event-driven: something happens when triggeredwait for event, then respond

Our chess board is event-driven. It does not care how long you think between moves. It only cares that you moved, and what you moved.

The Relationship: State and Event

Here is the essential pattern:

current state + event = new state
  1. There is a current state
  2. An event occurs
  3. The result is a new state

Or, visually:

state_0 event\xrightarrow{\text{event}} state_1

The arrow is the event. The boxes are states. This is the fundamental diagram of change.

Multiple Events

A chess game is not one event but many:

python
state_0 (initial)
    -> event: e2-e4
state_1
    -> event: e7-e5
state_2
    -> event: knight g1-f3
state_3
    -> ...

Each event transforms the state. The sequence of events is the history of the game. The final state is the result.

We now have a complete picture:

But we have not yet asked the crucial question: how does an event transform a state into a new state?

  • State: what is true at a moment
  • Event: what causes change
  • Sequence: one event after another

What happens in the moment of transition?

Try It Yourself

Try It Yourself

5 exercises to practice