MafiaEngine.Votes (mafia_engine v0.1.1)
This module defines the type for votes and functions to handle them.
Examples
iex> v = MafiaEngine.Votes.new("Annie")
...> jeff = MafiaEngine.Player.new("Jeff")
...> abed = MafiaEngine.Player.new("Abed")
...> {:ok, v} = MafiaEngine.Votes.vote(v, :guilty, jeff)
...> {:ok, v} = MafiaEngine.Votes.vote(v, :innocent, abed)
...> v.guilty
#MapSet<["Jeff"]>
iex> v.innocent
#MapSet<["Abed"]>
iex> MafiaEngine.Votes.result(v)
:innocent
iex> v = MafiaEngine.Votes.remove_vote(v, "Abed")
...> v.innocent
#MapSet<[]>
iex> MafiaEngine.Votes.result(v)
:guilty
Link to this section Summary
Functions
Creates votes data type with accused
as the accused.
Removes the vote from the given voter
if exists.
Returns :guilty
if there is more guilty votes and :innocent
otherwise.
Adds the vote
of voter
.
Link to this section Types
Specs
Link to this type
vote()
Specs
vote() :: :innocent | :guilty
Link to this section Functions
Link to this function
new(accused)
Specs
Creates votes data type with accused
as the accused.
Link to this function
remove_vote(votes, voter)
Specs
Removes the vote from the given voter
if exists.
Link to this function
result(votes)
Specs
Returns :guilty
if there is more guilty votes and :innocent
otherwise.
Link to this function
vote(votes, arg2, voter)
Specs
vote(t(), vote(), MafiaEngine.Player.t()) :: {:ok, t()} | {:error, :cannot_vote_while_dead | :accused_player_cannot_vote}
Adds the vote
of voter
.
Returns an error if the voter
is the accused or is not alive.
##Examples
iex> v = MafiaEngine.Votes.new("Annie")
...> annie = MafiaEngine.Player.new("Annie")
...> pierce = MafiaEngine.Player.new("Pierce")
...> pierce = MafiaEngine.Player.kill(pierce)
...> MafiaEngine.Votes.vote(v, :guilty, pierce)
{:error, :cannot_vote_while_dead}
iex> MafiaEngine.Votes.vote(v, :innocent, annie)
{:error, :accused_player_cannot_vote}