View Source Riot.LoR.Deck (Riot LoR v1.0.0)

Type and functions to represent a LoR deck, i.e., cards and their respective counts.

Link to this section Summary

Functions

Add a Riot.LoR.Card count to a Riot.LoR.Deck. By default it will increment the count by 1. You can increment by any positive integer.

Add a raw card code to a Riot.LoR.Deck. By default it will increment the count by 1. You can intrement by any positive integer.

Return a list of card codes and their counts.

Populate a new Riot.LoR.Deck from a list of cards and their counts.

Returns the minimum version required to support the cards in deck. If no minimum is found (e.g., the deck is empty), return the smallest version supported by the library.

Create an empty Riot.LoR.Deck

Remove a Riot.LoR.Card from a Riot.LoR.Deck. By default it will decrement the count by 1. You can can specify any positive integer to decrement the count by.

Link to this section Types

@type card_counts() :: [{binary(), pos_integer()}]
@type t() :: %{required(Riot.LoR.Card.t()) => pos_integer()}

Link to this section Functions

Link to this function

add_card(deck, card, count \\ 1)

View Source (since 1.0.0)
@spec add_card(t(), Riot.LoR.Card.t(), pos_integer()) :: t()

Add a Riot.LoR.Card count to a Riot.LoR.Deck. By default it will increment the count by 1. You can increment by any positive integer.

examples

Examples

iex> deck = Riot.LoR.Deck.new()
iex> deck = Riot.LoR.Deck.add_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 1})
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 1}
iex> deck = Riot.LoR.Deck.add_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 2}, 2)
%{
  %Riot.LoR.Card{fac: 0, num: 1, set: 1} => 1,
  %Riot.LoR.Card{fac: 0, num: 2, set: 1} => 2
}
iex> Riot.LoR.Deck.add_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 1}, 2)
%{
  %Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3,
  %Riot.LoR.Card{fac: 0, num: 2, set: 1} => 2
}
Link to this function

add_card_code!(deck, card_code, count \\ 1)

View Source (since 1.0.0)
@spec add_card_code!(t(), binary(), pos_integer()) :: t()

Add a raw card code to a Riot.LoR.Deck. By default it will increment the count by 1. You can intrement by any positive integer.

This is a convenience wrapper around Riot.LoR.Deck.add_card/3.

examples

Examples

iex> deck = Riot.LoR.Deck.new()
iex> deck = Riot.LoR.Deck.add_card_code!(deck, "01DE001")
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 1}
iex> Riot.LoR.Deck.add_card_code!(deck, "01DE001", 2)
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3}
Link to this function

code_count(deck)

View Source (since 1.0.0)
@spec code_count(t()) :: card_counts()

Return a list of card codes and their counts.

examples

Examples

iex> deck = Riot.LoR.Deck.new()
%{}
iex> deck = Riot.LoR.Deck.add_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 1}, 3)
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3}
iex> Riot.LoR.Deck.code_count(deck)
[{"01DE001", 3}]
Link to this function

from_card_counts!(card_counts)

View Source (since 1.0.0)
@spec from_card_counts!(card_counts()) :: t()

Populate a new Riot.LoR.Deck from a list of cards and their counts.

examples

Examples

iex> cards = [{"01DE001", 3}, {"01DE002", 2}]
iex> Riot.LoR.Deck.from_card_counts!(cards)
%{
  %Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3,
  %Riot.LoR.Card{fac: 0, num: 2, set: 1} => 2
}
Link to this function

min_required_version(deck)

View Source (since 1.0.0)
@spec min_required_version(t()) :: pos_integer()

Returns the minimum version required to support the cards in deck. If no minimum is found (e.g., the deck is empty), return the smallest version supported by the library.

examples

Examples

iex> cards = [{"03MT054", 1}, {"05BC198", 1}]
iex> deck = Riot.LoR.Deck.from_card_counts!(cards)
iex> Riot.LoR.Deck.min_required_version(deck)
4
@spec new() :: t()

Create an empty Riot.LoR.Deck

examples

Examples

iex> Riot.LoR.Deck.new()
%{}
Link to this function

remove_card(deck, card, count \\ 1)

View Source (since 1.0.0)
@spec remove_card(t(), Riot.LoR.Card.t(), pos_integer() | :all) :: t()

Remove a Riot.LoR.Card from a Riot.LoR.Deck. By default it will decrement the count by 1. You can can specify any positive integer to decrement the count by.

If you pass :all or an integer greater than or equal to the current count the Riot.LoR.Card will be removed from the Riot.LoR.Deck.

examples

Examples

iex> cards = [{"01DE001", 3}, {"01DE002", 2}, {"01DE003", 1}]
iex> deck = Riot.LoR.Deck.from_card_counts!(cards)
%{
  %Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3,
  %Riot.LoR.Card{fac: 0, num: 2, set: 1} => 2,
  %Riot.LoR.Card{fac: 0, num: 3, set: 1} => 1
}
iex> deck = Riot.LoR.Deck.remove_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 3})
%{
  %Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3,
  %Riot.LoR.Card{fac: 0, num: 2, set: 1} => 2
}
iex> deck = Riot.LoR.Deck.remove_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 2}, 2)
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 3}
iex> deck = Riot.LoR.Deck.remove_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 1})
%{%Riot.LoR.Card{fac: 0, num: 1, set: 1} => 2}
iex> Riot.LoR.Deck.remove_card(deck, %Riot.LoR.Card{set: 1, fac: 0, num: 1}, :all)
%{}