Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. import random
  2. import sys
  3.  
  4. BLACKJACK = 21
  5. ACE_IS_ELEVEN = 10
  6. ACE_IS_ONE = 11
  7.  
  8. cards = {'🂾': 10, '🂽': 10, '🂻': 10, '🂺': 10, '🂹': 9, '🂸': 8, '🂷': 7,
  9. '🂶': 6, '🂵': 5, '🂴': 4, '🂳': 3, '🂲': 2, '🂱': 'A', '🃎': 10,
  10. '🃍': 10, '🃋': 10, '🃊': 10, '🃉': 9, '🃈': 8, '🃇': 7, '🃆': 6,
  11. '🃅': 5, '🃄': 4, '🃃': 3, '🃂': 2, '🃁': 'A', '🂮': 10, '🂭': 10,
  12. '🂫': 10, '🂪': 10, '🂩': 9, '🂨': 8, '🂧': 7, '🂦': 6, '🂥': 5,
  13. '🂤': 4, '🂣': 3, '🂢': 2, '🂡': 'A', '🃞': 10, '🃝': 10, '🃛': 10,
  14. '🃚': 10, '🃙': 9, '🃘': 8, '🃗': 7, '🃖': 6, '🃕': 5, '🃔': 4,
  15. '🃓': 3, '🃒': 2, '🃑': 'A'}
  16.  
  17. card_faces = list(cards.keys())
  18.  
  19. shuffle_this_many_times = random.choice(range(3, 1024))
  20. for each in range(shuffle_this_many_times):
  21. random.shuffle(card_faces)
  22.  
  23. deck = [(card, cards[card]) for card in card_faces]
  24.  
  25. dealer_hand = []
  26. your_hand = []
  27. your_total = 0
  28. dealer_total = 0
  29. dealer_temp_total = 0
  30. user_lost = False
  31. dealer_lost = False
  32.  
  33. your_hand.append(deck[0][0])
  34. try:
  35. your_total += deck[0][1]
  36. except TypeError:
  37. if your_total + 11 > BLACKJACK:
  38. your_total += 1
  39. else:
  40. your_total += 11
  41. deck.pop(0)
  42.  
  43. dealer_hand.append(deck[0][0])
  44. try:
  45. dealer_total += deck[0][1]
  46. dealer_temp_total += deck[0][1]
  47. except TypeError:
  48. if dealer_total + 11 > BLACKJACK:
  49. dealer_total += 1
  50. dealer_temp_total += 11
  51. else:
  52. dealer_total += 11
  53. dealer_temp_total += 11
  54. deck.pop(0)
  55.  
  56. your_hand.append(deck[0][0])
  57. try:
  58. your_total += deck[0][1]
  59. except TypeError:
  60. if your_total + 11 > BLACKJACK:
  61. your_total += 1
  62. else:
  63. your_total += 11
  64. deck.pop(0)
  65.  
  66. dealer_hand.append(deck[0][0])
  67. try:
  68. dealer_total += deck[0][1]
  69. except TypeError:
  70. if dealer_total + 11 > BLACKJACK:
  71. dealer_total += 1
  72. else:
  73. dealer_total += 11
  74. deck.pop(0)
  75.  
  76. if your_total > 21:
  77. print(f'Your hand: {your_hand[0]}/{your_hand[1]} / Total: {your_total}')
  78. print(f'Dealer hand: {dealer_hand[0]}/{dealer_hand[1]} / Total: {dealer_total}')
  79. print('YOU LOST')
  80. user_lost = True
  81. sys.exit()
  82.  
  83. if dealer_total > 21:
  84. print(f'Dealer hand: {dealer_hand[0]}/{dealer_hand[1]} / Total: {dealer_total}')
  85. print('DEALER LOST')
  86. dealer_lost = True
  87. sys.exit()
  88.  
  89. if not user_lost or not dealer_lost:
  90. print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
  91. print(f'Dealer hand: {dealer_hand[0]}/? / Total: {dealer_temp_total}')
  92.  
  93. while your_total < 21:
  94. user_hit = input('Hit/Stand?: ').lower()
  95. if user_hit in ['h', 'hit', '0', 'first']:
  96. user_hit = True
  97. your_hand.append(deck[0][0])
  98. try:
  99. your_total += deck[0][1]
  100. except TypeError:
  101. if your_total + 11 > BLACKJACK:
  102. your_total += 1
  103. else:
  104. your_total += 11
  105. deck.pop(0)
  106.  
  107. if your_total > 21:
  108. print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
  109. print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
  110. print('YOU LOST')
  111. user_lost = True
  112. sys.exit()
  113. else:
  114. print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
  115. print(f'Dealer hand: {dealer_hand[0]}/? / Total: {dealer_temp_total}')
  116. else:
  117. break
  118.  
  119. while dealer_total <= 15:
  120. dealer_hand.append(deck[0][0])
  121. try:
  122. dealer_total += deck[0][1]
  123. except TypeError:
  124. if dealer_total + 11 > BLACKJACK:
  125. dealer_total += 1
  126. else:
  127. dealer_total += 11
  128. deck.pop(0)
  129.  
  130. if dealer_total > 21:
  131. print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
  132. print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
  133. print('DEALER LOST')
  134. dealer_lost = True
  135. else:
  136. print(f"Your hand: {'/'.join([your_hand[x] for x in range(len(your_hand))])} / Total: {your_total}")
  137. print(f"Dealer hand: {'/'.join([dealer_hand[x] for x in range(len(dealer_hand))])} / Total: {dealer_total}")
  138. if your_total <= BLACKJACK:
  139. if dealer_total >= your_total:
  140. print('DEALER WON')
  141. elif your_total > dealer_total:
  142. print('YOU WON')
  143. elif your_total == BLACKJACK:
  144. print('BLACKJACK!')
  145. else:
  146. if dealer_total <= BLACKJACK:
  147. print('DEALER WON')
  148. if dealer_total == BLACKJACK:
  149. print('DEALER BLACKJACK')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement