card_deck v0.1.0 CardDeck View Source

Documentation for CardDeck.

Link to this section Summary

Types

a card with a rank and suit {"A", "S"} Ace of Spades

A deck of cards - can be any lenght

one of: w[2 3 4 5 6 7 8 9 T J Q K A]

one of: [C D H S] clubs, diamnds, hearts, spades

Functions

Deals amount of card from deck

Drops cards at selected indexes

Drops cards at selected indexes to pile and returns pile and deck/hand

Returns new card deck

Returns rank of card

returns numeric value of a card

Shuffles the deck

returns shuffled deck

Returns size of deck

Sorts a deck by rank

Sorts a deck by rank

Sorts a deck by suit

returns card with numeric rank

Link to this section Types

Specs

card() :: {rank(), suit()}

a card with a rank and suit {"A", "S"} Ace of Spades

Specs

deck() :: [card()]

A deck of cards - can be any lenght

Specs

rank() :: String.t()

one of: w[2 3 4 5 6 7 8 9 T J Q K A]

Specs

suit() :: String.t()

one of: [C D H S] clubs, diamnds, hearts, spades

Link to this section Functions

Deals amount of card from deck

Examples

iex> CardDeck.new() |> CardDeck.deal() |> elem(0) [{"2", "C"}] iex> CardDeck.new() |> CardDeck.deal(5) |> elem(0) [{"2", "C"}, {"2", "D"}, {"2", "H"}, {"2", "S"}, {"3", "C"}] iex> CardDeck.new() |> CardDeck.deal(55) :error

Link to this function

drop(deck, positions_list)

View Source

Specs

drop(deck(), [integer()]) :: deck()

Drops cards at selected indexes

Examples

iex> CardDeck.new() |> CardDeck.drop([0,1,2,3]) |> hd {"3", "C"}

Link to this function

drop_to_pile(deck, positions_list)

View Source

Specs

drop_to_pile(deck(), [integer()]) :: {deck(), deck()}

Drops cards at selected indexes to pile and returns pile and deck/hand

# Examples [{"2", "C"}, {"2", "D"}, {"2", "H"}, {"2", "S"}] |> CardDeck.drop_to_pile([0,3]) {[{"2", "C"}, {"2", "S"}], [{"2", "D"}, {"2", "H"}]}

Specs

new() :: deck()

Returns new card deck

Examples

iex> hd CardDeck.new() {"2", "C"} iex> length CardDeck.new() 52

Returns rank of card

Examples

iex> CardDeck.rank({"T", "C"}) "T"

Specs

rank_value(card() | String.t()) :: integer()

returns numeric value of a card

Examples

iex> CardDeck.rank_value("T") < CardDeck.rank_value("K") true iex> CardDeck.rank_value({"T", "C"}) 10

Specs

shuffle(deck()) :: deck()

Shuffles the deck

Specs

shuffled() :: deck()

returns shuffled deck

Returns size of deck

Examples

iex> CardDeck.new() |> CardDeck.size() 52

Specs

sort(deck()) :: deck()

Sorts a deck by rank

Examples

iex> CardDeck.new() |> CardDeck.shuffle() |> CardDeck.sort() |> hd {"2", "C"}

Specs

sort_by_rank(deck()) :: deck()

Sorts a deck by rank

Examples

iex> CardDeck.sort_by_rank([{"T", "C"}, {"2", "D"}]) [{"2", "D"}, {"T", "C"}]

Specs

sort_by_suit(deck()) :: deck()

Sorts a deck by suit

Examples

iex> CardDeck.sort_by_suit([{"2", "D"}, {"9", "C"}]) [{"9", "C"}, {"2", "D"}]

Specs

to_value(card() | String.t()) :: {integer(), suit()}

returns card with numeric rank

Examples

iex> CardDeck.to_value({"A", "D"}) {14, "D"} iex> CardDeck.to_value({"T", "C"}) {10, "C"}