Skip to contents

This function sets up and plays a full game of UNO using standard rules. It creates the deck, deals cards to each player, and runs the game loop using `play_turns_loop()`. The game continues until one player wins or the deck runs out of cards.

Usage

play_game(n_players = 4)

Arguments

n_players

Number of players in the game (must be ≥ 2). Default is 4.

Value

A list containing:

winner

Name of the winning player (e.g., "Player_3"), or NULL if no player wins before the deck is exhausted

hands

Final hand of each player at the end of the game, as a named list of tibbles

discard

Final discard pile showing the full play history as a tibble with columns color, value, and type. Note: Wild cards (including wild and wild_draw4) will appear with the chosen color (e.g., color = "green" and value = "wild"), indicating the color selected by the player when the card was played.

Examples

# Run a game with 4 players
result <- play_game(4)

# See the winner
result$winner
#> [1] "Player_1"

# Preview the discard pile
head(result$discard)
#> <card_vctr[6]>
#> [1] <yellow_4>         <yellow_8>         <green_8>          <green_wild_draw4>
#> [5] <green_2>          <green_9>         

# Check final hand of Player 2
result$hands$Player_2
#> <card_vctr[2]>
#> [1] <green_9>   <wild_wild>