uno: Multiplayer UNO Game in R
Richi Susil Jacob, Pooja Rajendran Raju, Dhanshree Dhrafani
uno.Rmd
Introduction
The uno package lets you simulate a full multiplayer UNO game using realistic rules.
It supports:
Full UNO deck generation
Dealing hands to players
Turn-by-turn play using action and wild cards
Winner detection and scoring
Installation
You can install the development version of uno from GitHub using:
# Install devtools if not already installed
install.packages("devtools")
# Install uno from GitHub
devtools::install_github("MonashARP/game-package-kookaburras")
Create a Full UNO Deck
deck <- create_uno_deck()
head(deck)
#> # A tibble: 6 × 3
#> color value type
#> <chr> <chr> <chr>
#> 1 red 0 number
#> 2 red 1 number
#> 3 red 1 number
#> 4 red 2 number
#> 5 red 2 number
#> 6 red 3 number
nrow(deck) # Should return 108
#> [1] 108
This generates a standard 108-card deck including number cards (0–9), action cards (Skip, Reverse, +2), and wild cards (Wild, Wild Draw 4).
Deal Hands to Players
deal <- deal_hands(deck, n_players = 4)
# Explore hands
names(deal$hands)
#> [1] "Player_1" "Player_2" "Player_3" "Player_4"
deal$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
# View discard pile
deal$discard
#> # A tibble: 1 × 3
#> color value type
#> <chr> <chr> <chr>
#> 1 red 2 number
Each player is dealt 7 cards. The function returns:
A named list of player hands
The updated deck
A starting discard pile with one card
How Gameplay Works
The game logic is handled through two main functions:
-play_game() – Runs the full game from start to finish
-play_turns_loop() – Internal engine that manages turns, checks for playable cards, handles actions, and tracks the winner
The game proceeds automatically until one player finishes all cards. If the draw pile runs out before that, the game ends in a draw.
Simulate a Full Game
result <- play_game()
# View winner
result$winner
#> [1] "Player_1"
# Discard pile preview
tail(result$discard)
#> <card_vctr[6]>
#> [1] <red_wild> <red_5> <red_9> <blue_9> <blue_1> <blue_2>
The game runs automatically until one player wins by emptying their hand. All actions (skip, draw, reverse) are handled by the engine.
Note: Wild cards (wild, wild_draw4) appear in the discard pile with the color selected by the player who played them. For example, a card with value = “wild” and color = “green” means the player played a wild and chose green.
Access Individual Results
You can inspect any player’s hand:
result$hands$Player_2
#> <card_vctr[2]>
#> [1] <green_9> <wild_wild>
Or check the full discard pile history:
result$discard
#> <card_vctr[43]>
#> [1] <yellow_4> <yellow_8> <green_8> <green_wild_draw4>
#> [5] <green_2> <green_9> <red_9> <green_wild_draw4>
#> [9] <green_3> <red_wild_draw4> <red_6> <blue_3>
#> [13] <blue_2> <blue_3> <blue_6> <blue_7>
#> [17] <blue_1> <blue_0> <green_+2> <yellow_9>
#> [21] <yellow_7> <yellow_0> <yellow_skip> <yellow_1>
#> [25] <red_1> <red_1> <red_+2> <red_8>
#> [29] <red_3> <red_7> <red_7> <green_7>
#> [33] <green_5> <red_2> <red_6> <red_+2>
#> [37] <red_2> <red_wild> <red_5> <red_9>
#> [41] <blue_9> <blue_1> <blue_2>
Available Functions
Function | Description |
---|---|
create_uno_deck() |
Generate a 108-card UNO deck |
deal_hands() |
Deal 7 cards to each player |
play_game() |
Full simulation: setup + play to winner |
play_turns_loop() |
Internal game loop handling each player’s turn |