perudox v0.1.0 Perudox.Player.State
This module defines state for a player and facilitates interactions with it.
Summary
Functions
Removes a dice from a player’s hand. If their last dice is being taken, the state is also maked as game over
Counts occurences of each value in a hand
Rolls the hand in the given state
Adds a dice to a hand, unless that player is out or his hand is maxed out
Types
Functions
Removes a dice from a player’s hand. If their last dice is being taken, the state is also maked as game over.
Examples
iex> hand = [1, 2, 3, 4]
iex> state = %Perudox.Player.State{hand: hand}
iex> %{hand: new_hand} = Perudox.Player.State.lose_a_dice state
iex> hand != new_hand && length(hand) == length(new_hand) + 1
true
Counts occurences of each value in a hand.
Examples
iex> hand = [1, 2, 2, 3, 3, 3]
iex> state = %Perudox.Player.State{hand: hand}
iex> Perudox.Player.State.occurences state
%{1 => 1, 2 => 2, 3 => 3, 4 => 0, 5 => 0, 6 => 0}
Rolls the hand in the given state.
Examples
iex> hand = [5, 6, 7]
iex> state = %Perudox.Player.State{hand: hand}
iex> %{hand: new_hand} = Perudox.Player.State.roll state
iex> hand != new_hand && length(hand) == length(new_hand)
true