The Players Set
Learn how the players join the game.
We'll cover the following...
The :players_set
module
At this point, the second player has joined the game so we are in the :players_set
state. In the :players_set
state, the players can position and reposition their islands on the board without transitioning the state.
They can also set their islands and declare their positions that will be fixed for the rest of the game. When only one player has set their islands, the game remains in the :players_set
state. When the second player sets his islands, the game transitions to the :player1_turn
state. That’s when the game really begins.
We will focus on the transition from :players_set
to :player1_turn
and the aforementioned events.
Let’s begin by defining a check/2
clause for players positioning their islands.
The idea that we would like to express with this clause is that when the game is in the :players_set
state, it’s okay for either player to position their islands:
def check(%Rules{state: :players_set} = rules, {:position_islands, player}) do
{:ok, rules}
end
That definition seems fine, but there’s a subtlety here we need to capture.
The rules of the :players_set
state
Players can move their island at any time until they set them. Both players are almost certain to set their islands at different times. If Player 1 has set their islands but Player 2 hasn’t, Player 1 should no longer be able to move their islands. However, Player 2 should still be able to move their islands. While this condition ...