Skip to contents

This function simulates the dealer's turn in a Blackjack game, where the dealer draws cards based on specific rules.

Usage

dealer_turn_smart(dealer_hand, player_hand, deck)

Arguments

dealer_hand

A vector representing the dealer's current hand.

player_hand

A vector representing the player's current hand.

deck

A vector representing the remaining deck of cards.

Value

A list containing:

hand

The final dealer hand after drawing cards.

deck

The updated deck after removing drawn cards.

total

The final total value of the dealer's hand.

Details

The dealer will keep drawing cards until: - The dealer's hand value is 17 or higher. - The dealer's hand value is equal to 17 but contains an Ace valued at 11. - The dealer's hand value is less than the player's hand value. If the player has already busted (hand value over 21), the dealer will not draw any more cards and automatically wins.

Examples

# Create a shuffled deck
deck <- create_shuffled_deck()

# Deal initial hands for player and dealer
player_result <- deal_hand(deck, 2)
player_hand <- player_result$hand
deck <- player_result$deck

dealer_result <- deal_hand(deck, 2)
dealer_hand <- dealer_result$hand
deck <- dealer_result$deck

# Run dealer's smart turn
result <- dealer_turn_smart(dealer_hand, player_hand, deck)
result$hand   # Final dealer hand
#> card[3]
#> 3♦ A♥ 3♥ 
result$total  # Dealer's total score
#> [1] 17