Set the Islands

Let’s try the functionality to set the islands.

Set the players’ islands

Once the players are done positioning their islands, they mark them as a set. After that, they can no longer move the islands around the board.

The game itself doesn’t track this. Only the Rules module knows whether players have set their islands. But the Board module has a role to play in the decision. It knows whether or not players have positioned all their islands.

The Rules module cares that the state is in :players_set, and it cares that players have not already set their islands.

The decision as to whether players should be able to set their islands depends partly on the Rules and partly on the Board—whether or not players have positioned all their islands.

We’ll test these two conditions in our with/1 clause. Let’s begin with the public interface function set_islands/2. Since this action is per player, we need it to take the player as an argument in addition to the game PID:

def set_islands(game, player) when player in @players, do:
  GenServer.call(game, {:set_islands, player})

Get hands-on with 1200+ tech skills courses.