View Source Perudex.Hand (Perudex v0.7.0)

Provides functions to manipulate a hand of dice in Perudex.

Link to this section Summary

Functions

Add a die to the hand if the maximum defined by game rules is not busted.

Initialize a new hand for a player given his allowed dice holding count.

Remove a die from the hand if it is not empty. Set has_palificoed to true if the player is dropping to his last die.

Link to this section Types

@type die() :: 1..6
@type t() :: %Perudex.Hand{
  dice: [die()],
  has_palificoed: boolean(),
  remaining_dice: integer()
}

Link to this section Functions

Add a die to the hand if the maximum defined by game rules is not busted.

examples

Examples:

iex> Perudex.Hand.add(%Perudex.Hand{remaining_dice: 4})
%Perudex.Hand{remaining_dice: 5, dice: nil}

Initialize a new hand for a player given his allowed dice holding count.

examples

Examples:

iex> hand = Perudex.Hand.new(%Perudex.Hand{remaining_dice: 5})
iex> %{remaining_dice: 5} = hand
iex> length(hand.dice) == hand.remaining_dice

Remove a die from the hand if it is not empty. Set has_palificoed to true if the player is dropping to his last die.

examples

Examples:

iex> Perudex.Hand.take(%Perudex.Hand{remaining_dice: 5})
%Perudex.Hand{remaining_dice: 4, dice: nil, has_palificoed: false}

iex> Perudex.Hand.take(%Perudex.Hand{remaining_dice: 0})
%Perudex.Hand{remaining_dice: 0, dice: nil, has_palificoed: false}

iex> Perudex.Hand.take(%Perudex.Hand{remaining_dice: 2})
%Perudex.Hand{remaining_dice: 1, dice: nil, has_palificoed: true}