Working Through the States

With the catchall in place, all we need to do from now on is define the positive cases. We’ll add a new clause of check/2 for each new state/event pair that we want to add to the whitelist. By the end of this section, we will have a complete state machine that will describe all the rules of Islands.

Let’s start with the first state, :initialized.

Initialized

When we’re in :initialized, the only permissible action is adding the second player. We’re going to focus on that one action and the transition it triggers, from :initialized to :players_set.

images/state_machine/initialized-players_set.png

We’ll need a clause of check/2 for this that adds this combination of state ...

Get Functional Web Development with Elixir, OTP, and Phoenix now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.