Skip to contents

This function simulates a complete round of Blackjack between one or more players and a dealer. Each player is dealt two cards and follows a simple decision strategy (e.g., hit on low scores). The dealer plays according to standard rules, including hitting on soft 17.

Usage

simulate_blackjack_game(num_players = 1, seed = NULL)

Arguments

num_players

Integer. Number of players in the game (default is 1).

seed

Optional integer. If provided, sets the random seed for reproducibility.

Value

A structured list of class "blackjack_game" containing:

players

A list of player results. Each contains the player's hand, final score, and outcome message.

dealer

A list with the dealer's final hand and score.

Details

Each player acts independently and uses a basic AI decision rule: hit below 12, stand at 17+, and probabilistic decisions between 12–16. The dealer continues hitting until reaching 17 or more, and hits on a soft 17.

Examples

simulate_blackjack_game(num_players = 2, seed = 123)
#> Dealer's hand:  6♦ 3♥ A♥ 
#> Dealer's score:  20 
#> 
#> Player 1 hand: 2♥ 4♠ Q♦ Q♣
#> Player 1 score: 26
#> Player 1 result: Player busts! Dealer wins.
#> 
#> Player 2 hand: 4♣ 5♣ K♥
#> Player 2 score: 19
#> Player 2 result: Dealer wins!
#>