MafiaEngine.Accusations (mafia_engine v0.1.1)
This module defines the type for accusations and functions to handle them.
Examples
iex> a = MafiaEngine.Accusations.new(2) %MafiaEngine.Accusations{ballots: %{}, required: 2} iex> abed = MafiaEngine.Player.new("Abed") ...> jeff = MafiaEngine.Player.new("Jeff") ...> {:ok, a} = MafiaEngine.Accusations.accuse(a, abed, jeff) {:ok, %MafiaEngine.Accusations{ballots: %{"Abed" => "Jeff"}, required: 2}} iex> a = MafiaEngine.Accusations.withdraw(a, "Abed") %MafiaEngine.Accusations{ballots: %{}, required: 2} iex> {:ok, a} = MafiaEngine.Accusations.accuse(a, jeff, abed) ...> MafiaEngine.Accusations.accuse(a, abed, abed) {:accused, "Abed", %MafiaEngine.Accusations{ ballots: %{"Abed" => "Abed", "Jeff" => "Abed"}, required: 2 }}
Link to this section Summary
Functions
Adds the accusation from accuser
to accused
.
It also checks if accused has the required accusations to be accused.
Creates a new accusations with required
as the number of accusations required to cause a player to be accused.
Removes the accusation from accuser
if exists.
Link to this section Types
Specs
t() :: %MafiaEngine.Accusations{ ballots: %{optional(String.t()) => String.t()}, required: pos_integer() }
Link to this section Functions
accuse(accusations, accuser, accused)
Specs
accuse(t(), MafiaEngine.Player.t(), MafiaEngine.Player.t()) :: {:ok, t()} | {:accused, String.t(), t()} | {:error, :cannot_accuse_while_dead | :cannot_accuse_dead_players}
Adds the accusation from accuser
to accused
.
It also checks if accused has the required accusations to be accused.
Returns an error if either accuser
or accused
is not alive.
Examples
iex> a = MafiaEngine.Accusations.new(2)
...> jeff = MafiaEngine.Player.new("Jeff")
...> pierce = MafiaEngine.Player.new("Pierce")
...> pierce = MafiaEngine.Player.kill(pierce)
...> MafiaEngine.Accusations.accuse(a, pierce, jeff)
{:error, :cannot_accuse_while_dead}
iex> MafiaEngine.Accusations.accuse(a, jeff, pierce)
{:error, :cannot_accuse_dead_players}
new(required)
Specs
new(pos_integer()) :: t()
Creates a new accusations with required
as the number of accusations required to cause a player to be accused.
withdraw(accusations, accuser)
Specs
Removes the accusation from accuser
if exists.