Player Two’s Turn

Learn to tackle the second player's turn.

We'll cover the following

:player2_turn

This state is the mirror image of :player1_turn. When it’s the second player’s turn, they can guess a coordinate or win the game. No other events are permissible. Much of this will seem familiar since we need the same two clauses we defined for :player1_turn and :player1. However, this time we need it for :player2_turn and :player2.

The first clause should say that when the state is :player2_turn, :player2 is allowed to guess. This guess transitions the state to :player1_turn:

def check(%Rules{state: :player2_turn} = rules, {:guess_coordinate, :player2}), do:
  {:ok, %Rules{rules | state: :player1_turn}}

Get hands-on with 1200+ tech skills courses.