Untitled
unknown
plain_text
3 years ago
1.2 kB
6
Indexable
// Set up the deck of cards
deck = create_deck()
// Shuffle the deck
shuffle_deck(deck)
// Deal two cards to the player and the dealer
player_hand = deal_cards(deck, 2)
dealer_hand = deal_cards(deck, 2)
// Check if the player has blackjack
if has_blackjack(player_hand):
print("Blackjack! You win!")
end_game()
// Allow the player to hit or stand
while True:
print("Your hand:", player_hand)
print("Dealer's hand:", dealer_hand[0])
action = get_player_action()
if action == "hit":
player_hand.append(deal_cards(deck, 1)[0])
if get_hand_value(player_hand) > 21:
print("Bust! You lose.")
end_game()
elif action == "stand":
break
// Dealer takes hits until their hand is at least 17
while get_hand_value(dealer_hand) < 17:
dealer_hand.append(deal_cards(deck, 1)[0])
// Determine the winner
player_value = get_hand_value(player_hand)
dealer_value = get_hand_value(dealer_hand)
if player_value > 21:
print("Bust! You lose.")
elif dealer_value > 21:
print("Dealer busts! You win!")
elif player_value > dealer_value:
print("You win!")
elif dealer_value > player_value:
print("You lose.")
else:
print("It's a tie!")
// End the game
end_game()
Editor is loading...