Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import sys
- BLACKJACK = 21
- ACE_IS_ELEVEN = 10
- ACE_IS_ONE = 11
- cards = {'🂾': 10, '🂽': 10, '🂻': 10, '🂺': 10, '🂹': 9, '🂸': 8, '🂷': 7,
- '🂶': 6, '🂵': 5, '🂴': 4, '🂳': 3, '🂲': 2, '🂱': 'A', '🃎': 10,
- '🃍': 10, '🃋': 10, '🃊': 10, '🃉': 9, '🃈': 8, '🃇': 7, '🃆': 6,
- '🃅': 5, '🃄': 4, '🃃': 3, '🃂': 2, '🃁': 'A', '🂮': 10, '🂭': 10,
- '🂫': 10, '🂪': 10, '🂩': 9, '🂨': 8, '🂧': 7, '🂦': 6, '🂥': 5,
- '🂤': 4, '🂣': 3, '🂢': 2, '🂡': 'A', '🃞': 10, '🃝': 10, '🃛': 10,
- '🃚': 10, '🃙': 9, '🃘': 8, '🃗': 7, '🃖': 6, '🃕': 5, '🃔': 4,
- '🃓': 3, '🃒': 2, '🃑': 'A'}
- card_faces = list(cards.keys())
- shuffle_this_many_times = random.choice(range(3, 1024))
- for each in range(shuffle_this_many_times):
- random.shuffle(card_faces)
- deck = [(card, cards[card]) for card in card_faces]
- dealer_hand = []
- your_hand = []
- your_total = 0
- dealer_total = 0
- dealer_temp_total = 0
- user_lost = False
- dealer_lost = False
- your_hand.append(deck[0][0])
- try:
- your_total += deck[0][1]
- except TypeError:
- if your_total + 11 > BLACKJACK:
- your_total += 1
- else:
- your_total += 11
- deck.pop(0)
- dealer_hand.append(deck[0][0])
- try:
- dealer_total += deck[0][1]
- dealer_temp_total += deck[0][1]
- except TypeError:
- if dealer_total + 11 > BLACKJACK:
- dealer_total += 1
- dealer_temp_total += 11
- else:
- dealer_total += 11
- dealer_temp_total += 11
- deck.pop(0)
- your_hand.append(deck[0][0])
- try:
- your_total += deck[0][1]
- except TypeError:
- if your_total + 11 > BLACKJACK:
- your_total += 1
- else:
- your_total += 11
- deck.pop(0)
- dealer_hand.append(deck[0][0])
- try:
- dealer_total += deck[0][1]
- except TypeError:
- if dealer_total + 11 > BLACKJACK:
- dealer_total += 1
- else:
- dealer_total += 11
- deck.pop(0)
- if your_total > 21:
- print(f'Your hand: {your_hand[0]}/{your_hand[1]} / Total: {your_total}')
- print(f'Dealer hand: {dealer_hand[0]}/{dealer_hand[1]} / Total: {dealer_total}')
- print('YOU LOST')
- user_lost = True
- sys.exit()
- if dealer_total > 21:
- print(f'Dealer hand: {dealer_hand[0]}/{dealer_hand[1]} / Total: {dealer_total}')
- print('DEALER LOST')
- dealer_lost = True
- sys.exit()
- if not user_lost or not dealer_lost:
- print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
- print(f'Dealer hand: {dealer_hand[0]}/? / Total: {dealer_temp_total}')
- while your_total < 21:
- user_hit = input('Hit/Stand?: ').lower()
- if user_hit in ['h', 'hit', '0', 'first']:
- user_hit = True
- your_hand.append(deck[0][0])
- try:
- your_total += deck[0][1]
- except TypeError:
- if your_total + 11 > BLACKJACK:
- your_total += 1
- else:
- your_total += 11
- deck.pop(0)
- if your_total > 21:
- print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
- print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
- print('YOU LOST')
- user_lost = True
- sys.exit()
- else:
- print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
- print(f'Dealer hand: {dealer_hand[0]}/? / Total: {dealer_temp_total}')
- else:
- break
- while dealer_total <= 15:
- dealer_hand.append(deck[0][0])
- try:
- dealer_total += deck[0][1]
- except TypeError:
- if dealer_total + 11 > BLACKJACK:
- dealer_total += 1
- else:
- dealer_total += 11
- deck.pop(0)
- if dealer_total > 21:
- print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
- print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
- print('DEALER LOST')
- dealer_lost = True
- else:
- print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
- print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
- if your_total <= BLACKJACK:
- if dealer_total >= your_total:
- print('DEALER WON')
- elif your_total > dealer_total:
- print('YOU WON')
- elif your_total == BLACKJACK:
- print('BLACKJACK!')
- else:
- if dealer_total <= BLACKJACK:
- print('DEALER WON')
- if dealer_total == BLACKJACK:
- print('DEALER BLACKJACK')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement