Automatic Player Turn Logic
auto_player_turn.Rd
This function simulates the player's turn in a Blackjack game. The player keeps drawing cards until the total hand value reaches or exceeds a specific threshold.
Value
A list containing:
- hand
The updated player hand after drawing cards.
- deck
The updated deck after removing drawn cards.
- total
The final total value of the player's hand.
Details
Work basically the same as dealer_turn but with threshold input by user instead of fixed 17 rule. Call deal_hand() to draw card so it use the same logic from deal_turn as well
Examples
# 1) Start with a fresh shuffled deck:
deck <- create_shuffled_deck()
# 2) Deal two cards to form the initial player hand:
top_two <- deal_hand(deck, 2)
hand <- top_two$hand
deck <- top_two$deck
# 3) Now call auto_player_turn() with threshold = 17:
auto_player_turn(player_hand = hand, deck = deck, threshold = 17)
#> $hand
#> card[3]
#> 5♥ 9♣ 10♣
#>
#> $deck
#> card[205]
#> Q♠ Q♣ 8♠ 9♣ 4♠ 2♣ 3♣ 6♠ Q♥ 2♦ K♥ A♥ 9♦ 4♠ 3♥ J♠ 5♣ 4♣ 6♣ 9♦ 6♥ 5♠ 7♠ 8♠ 8♦ 6♦ 7♦ 4♦ 10♠ 8♣ J♠ 5♠ A♠ 2♦ 5♥ 10♥ 5♣ K♥ 10♥ 4♥ A♠ K♥ 9♠ 6♠ 5♠ 6♦ 2♣ 3♦ 10♣ J♥ 10♦ K♦ 10♦ 3♠ 2♦ K♦ 10♠ 5♦ 5♣ 3♠ K♠ 2♣ K♠ 3♣ 4♣ 2♥ Q♣ K♣ A♥ 9♠ 2♥ 7♦ Q♠ J♣ 10♦ A♠ 7♣ 8♦ A♦ 5♦ J♥ 5♥ J♦ Q♠ Q♥ J♦ 8♠ J♥ J♦ 5♦ 8♥ 9♥ K♣ 2♠ 8♠ 8♥ 6♠ 9♠ 2♠ K♣ 7♣ 10♥ 2♥ K♥ 3♦ K♠ K♦ A♣ 4♣ 7♥ Q♥ 10♠ K♣ 10♥ Q♣ 2♠ A♦ 8♦ 7♣ 4♠ 3♥ J♣ Q♠ A♦ Q♦ 6♥ Q♦ 2♣ 3♥ 6♦ 3♠ 7♠ 4♦ 3♥ Q♥ J♦ 8♥ Q♦ 3♦ 5♠ A♣ 6♠ 3♣ 9♦ 6♦ J♠ J♣ 6♥ 7♥ 5♣ 7♥ 9♥ J♠ 3♣ A♣ 6♣ 4♠ 8♣ 7♦ J♥ Q♦ 4♥ 10♠ 3♦ A♥ A♣ 3♠ 8♣ 9♦ 4♥ A♥ 7♠ 4♣ 9♣ 6♥ 8♦ 4♦ 2♠ 9♥ 5♦ 5♥ K♠ 6♣ K♦ 4♥ 8♣ 9♠ 2♥ 9♣ Q♣ 8♥ 4♦ 7♠ 10♣ 7♦ J♣ 2♦ 7♣ 10♣ 9♥ 6♣ A♠ A♦ 7♥ 10♦
#>
#> $total
#> [1] 24
#>