Cards v0.1.0 Cards View Source
Provides methods for creating and handling a deck of cards.
Link to this section Summary
Functions
Returns true if deck contains a given card, otherwise false.
Generates a standard 52-card deck as a list of strings.
Divides a deck into a hand and the remainder of the deck.
The hand_size argument indicates how many cards should be in the hand.
Returns a tuple with two lists. The first list contains number of cards
split from the deck. The second list contains the remaining deck of cards.
This function utilizes the Elixir Enum module split function.
Returns a tuple with {hand, deck} where hand has hand_size number of cards.
Load a deck of cards from the specified filename. If the file
does not exist
Save a deck of cards to the specified filename for future access.
Shuffles a deck of cards using the Elixir Enum module shuffle function.
Link to this section Functions
contains?(deck, card) View Source
Returns true if deck contains a given card, otherwise false.
Examples
iex> deck = Cards.create_deck
iex> Cards.contains?(deck, "Ace of Hearts")
true
iex> Cards.contains?(deck, "Eleven of Hearts")
false
create_deck() View Source
Generates a standard 52-card deck as a list of strings.
Examples
iex> length(Cards.create_deck)
52
deal(deck, hand_size) View Source
Divides a deck into a hand and the remainder of the deck.
The hand_size argument indicates how many cards should be in the hand.
Returns a tuple with two lists. The first list contains number of cards
split from the deck. The second list contains the remaining deck of cards.
This function utilizes the Elixir Enum module split function.
Examples
iex> deck = Cards.create_deck
iex> {hand, _deck} = Cards.deal(deck, 2)
iex> hand
["Ace of Diamonds", "Ace of Hearts"]
hand(hand_size) View Source
Returns a tuple with {hand, deck} where hand has hand_size number of cards.
Examples
iex> {hand, _deck} = Cards.hand(2)
iex> length(hand)
2
load(filename) View Source
Load a deck of cards from the specified filename. If the file
does not exist
Examples
iex> {hand, _deck} = Cards.hand(3)
iex> Cards.save(hand, "deck.txt")
iex> deck = Cards.load("deck.txt")
iex> length(deck)
3
iex> Cards.load("fake_deck.txt")
"File 'fake_deck.txt' does not exist"
save(deck, filename) View Source
Save a deck of cards to the specified filename for future access.
Examples
iex> deck = Cards.create_deck
iex> Cards.save(deck, "deck.txt")
:ok
shuffle(deck) View Source
Shuffles a deck of cards using the Elixir Enum module shuffle function.
Examples
iex> deck = Cards.create_deck
iex> shuffled_deck = Cards.shuffle(deck)
iex> deck != shuffled_deck
true