Skip to contents

Shuffles the full UNO deck and deals 7 cards to each player. After dealing, the next card from the deck is used to start the discard pile, and the remaining cards form the draw pile. Player hands are returned as a named list, and the function ensures there are enough cards to support the number of players.

Usage

deal_hands(deck, n_players = 4)

Arguments

deck

A tibble of UNO cards, typically created using create_uno_deck().

n_players

Number of players (must be 2 or more). Defaults to 4.

Value

A list with three components:

hands

A named list of tibbles, each with 7 cards for one player

deck

A tibble of remaining cards (the draw pile)

discard

A one-row tibble representing the initial discard card

Details

This function is typically called during game setup, after generating the deck using create_uno_deck.

Examples

deck <- create_uno_deck()
result <- deal_hands(deck, n_players = 4)

# View Player 1's hand
result$hands$Player_1
#> # A tibble: 7 × 3
#>   color  value type  
#>   <chr>  <chr> <chr> 
#> 1 blue   3     number
#> 2 green  2     number
#> 3 yellow 9     number
#> 4 yellow 3     number
#> 5 wild   wild  wild  
#> 6 wild   wild  wild  
#> 7 blue   4     number

# Check the discard card
result$discard_one
#> NULL

# Number of cards left in the draw pile
nrow(result$deck)
#> [1] 79

# Validate hand sizes
sapply(result$hands, nrow)
#> Player_1 Player_2 Player_3 Player_4 
#>        7        7        7        7