Skip to contents

Deals cards from a given deck and removes them from the deck using C++ for performance. If the deck fall below 25

Usage

deal_hand(deck, n = 2)

Arguments

deck

A deck of cards, typically the output of create_shuffled_deck(). Internally, this should be a vctrs record with class "card" (each element has fields name, rank, suit_symbol, suit, is_face) or a plain character vector of card names.

n

Number of cards to deal (default = 2).

Value

A list with:

hand

Character vector or "card" record of dealt cards depend on the deck used.

deck

The updated deck after removing dealt cards.

Details

After the update, deal_hand() is now an S3 generic with methods for both card records and the old character. If the user use this deal_hand() with a character vector, it will still work as before, however, it lack the ability to check with create_shuffle_deck for whether the amount of cards fall below 25 If deck inherits from class "card", it dispatch to deal_hand.card(). If deck is a bare character vector, it dispatch to deal_hand.character(). If is an unexpected class then it dispatch to deal_hand.default() which throws an error.

Examples

# Create a shuffled deck and deal a hand of 2 cards
deck <- create_shuffled_deck()
result <- deal_hand(deck, 2)
result$hand
#> card[2]
#> K♣ 6♦ 
length(result$deck)
#> [1] 206
# Automatic reshuffle
small_deck <- head(create_shuffled_deck(), 6)
deal_hand(small_deck, 2)
#> creating new deck...
#> $hand
#> card[2]
#> 2♥ A♥ 
#> 
#> $deck
#> card[206]
#> 3♣ 7♣ K♦ 2♥ 6♦ 5♠ J♣ 2♣ J♥ 8♣ 4♦ 7♥ 7♥ 7♣ 3♠ 7♠ A♦ K♦ 4♥ 8♦ 10♦ 5♥ A♠ 4♦ Q♣ 6♣ Q♠ J♦ 2♠ J♠ 2♣ 4♠ A♣ 3♠ 8♦ 8♠ 5♠ K♠ 8♦ Q♦ 9♠ 7♠ 10♣ A♥ Q♦ 9♥ 5♦ 5♠ 4♠ K♠ Q♦ 5♣ 8♠ Q♥ 4♥ Q♣ J♣ 4♣ 6♦ K♣ 4♠ 9♥ K♠ 6♥ 4♥ 5♣ A♠ 2♠ 6♠ 3♦ Q♠ 8♣ 3♠ 2♦ 10♠ 4♣ 2♥ 9♣ J♠ 10♦ 3♦ 8♥ Q♥ 3♥ 10♥ A♣ 4♦ K♥ 4♣ 10♥ 9♦ 6♥ 6♣ 6♦ 6♥ J♥ 8♣ 10♣ 2♣ 8♦ A♣ 10♣ 6♠ 9♠ 5♦ K♣ J♦ Q♥ 3♥ 4♥ 9♣ 8♥ 7♥ 3♥ K♥ J♦ 6♥ 5♥ 10♠ 3♠ 2♦ 9♣ 2♦ 3♥ 7♥ K♥ 10♣ 10♦ 9♦ 5♥ 9♥ Q♦ K♥ K♣ 7♦ 9♣ 10♠ 6♠ 4♠ 5♦ 9♠ 3♦ 3♦ 10♥ 8♠ 6♠ 3♣ J♣ 6♣ A♦ 9♦ Q♥ A♦ A♠ A♠ K♣ 3♣ K♦ 10♥ 7♠ 8♥ 6♦ 2♥ A♣ J♥ Q♠ 8♠ J♣ Q♠ 2♠ 5♦ 5♣ 10♠ J♦ Q♣ A♥ 5♥ 4♣ 2♦ 7♣ J♠ 7♦ 8♣ 2♣ 2♠ K♦ 9♦ 3♣ J♥ J♠ 7♠ K♠ 8♥ 5♠ 7♦ Q♣ 7♦ 6♣ A♦ 7♣ 4♦ 10♦ 5♣ 9♠ A♥ 9♥ 
#>