Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. #! python 3
  2. # Deal or No Deal Terminal Game created by James Robertson - github.com/jamesurobertson
  3.  
  4. print('''
  5. A termianl version of Deal or No Deal.
  6. The game rules:
  7. The game starts with 26 cases.
  8. Each case holds a value of .01 - 1,000,000
  9. .01 1,000
  10. 1 5,000
  11. 5 10,000
  12. 10 25,000
  13. 25 50,000
  14. 50 75,000
  15. 75 100,000
  16. 100 200,000
  17. 200 300,000
  18. 300 400,000
  19. 400 500,000
  20. 500 750,000
  21. 750 1,000,000
  22.  
  23. At the start of the game you choose a random case with a hidden value
  24. After choosing a case, there are multiple rounds and the option of making
  25. a deal with the banker between rounds.\n''')
  26.  
  27. import random, pprint, sys
  28.  
  29. # To strikethrough text
  30. def strike(text):
  31. result = ''
  32. for c in text:
  33. result = result + c + '\u0336'
  34. return result
  35.  
  36. # At Shuffle the dollar amounts into random cases
  37. def shuffle_cases():
  38. dollar_amounts = ['1', '5', '10', '25', '50', '75', '100', '200', '300', '400',
  39. '500', '750', '1000', '5000', '10000', '25000', '50000', '75000', '100000',
  40. '200000', '300000', '400000', '500000', '750000', '1000000']
  41.  
  42. random.shuffle(dollar_amounts)
  43. for i in range(len(dollar_amounts)):
  44. cases[i + 1] = dollar_amounts[i]
  45.  
  46.  
  47. # The bank offer after each round. calculation based off a reddit post I found.
  48. def bank_offer(remaining_amounts, round_number, players_case):
  49.  
  50. # Amounts left that are <= 75,000
  51. remining_low_amounts_sum = 0
  52. # Amounts left that are >= 100,000
  53. remining_high_amounts_sum = 0
  54.  
  55.  
  56. additional_calculation_per_round = {1: .13, 2:.17, 3: .2, 4:.25, 5:.33, 5:.33, 6:.33, \
  57. 7: .33, 8: .33, 9: .33, 10: .33, 11: .33}
  58. additiona_high_amount_calcuation_per_round = {1: .11, 2: .16, 3: .21, 4: .26, 5: .31, 6:.32, \
  59. 7: .33, 8: .34, 9: .35, 10: .36, 11: .37}
  60.  
  61. # Calculating the totals for low/high remaining_amounts left
  62. for value in remaining_amounts.values():
  63. if int(value) <= 75000:
  64. remining_low_amounts_sum += int(value)
  65. else:
  66. remining_high_amounts_sum += int(value)
  67.  
  68. if int(players_case) < 75000:
  69. remining_low_amounts_sum += int(players_case)
  70. else:
  71. remining_high_amounts_sum += int(players_case)
  72.  
  73. round_calc = additiona_high_amount_calcuation_per_round[round_number]
  74. high_round_calc = additiona_high_amount_calcuation_per_round[round_number]
  75.  
  76. # The bank's offer calculation
  77. bank_offer = round((remining_low_amounts_sum * round_calc) \
  78. + (remining_high_amounts_sum * round_calc * high_round_calc))
  79.  
  80. print(f'\nThe bank offers ${bank_offer} Do you want to make the deal?')
  81. print('DEAL OR NO DEAL? Press "enter" for NO DEAL! Type (d)eal for Deal.', end='')
  82. answer = input()
  83.  
  84. while answer != '' and answer != 'd':
  85. print("Please press 'enter' or type 'd' for deal.", end='')
  86. answer = input()
  87.  
  88. if answer == 'd':
  89. print(f'Congratulations! You won {bank_offer}!! Please play again soon :) ')
  90. sys.exit()
  91. else:
  92. print(f"\nNO DEAL! Time for round #{round_number + 1} ")
  93.  
  94. def print_remaining_cases(remaining_dict):
  95. remaining_cases = []
  96.  
  97. for k in remaining_dict.keys():
  98. remaining_cases += [int(k)]
  99.  
  100. remaining_cases = sorted(remaining_cases)
  101. remaining_cases_string = ''
  102.  
  103. for i in remaining_cases:
  104. if i == remaining_cases[-1]:
  105. remaining_cases_string += str(i)
  106. else:
  107. remaining_cases_string += str(i) + ', '
  108.  
  109. print(f'Remaining cases: {remaining_cases_string}')
  110.  
  111. def print_remaining_values(remaining_dict):
  112. remaining_values = []
  113.  
  114. for v in remaining_dict.values():
  115. if len(remaining_dict) == 1:
  116. print(f'You won {v}. Thanks for playing')
  117. sys.exit()
  118. else:
  119. remaining_values += [int(v)]
  120.  
  121. remaining_values = sorted(remaining_values)
  122. remaining_values_string = ''
  123.  
  124. for i in remaining_values:
  125. if i == remaining_values[-1]:
  126. remaining_values_string += str(i)
  127. else:
  128. remaining_values_string += str(i) + ', '
  129.  
  130. print(f'Remaining values: {remaining_values_string}')
  131.  
  132. # Main Game Loop
  133.  
  134. while True:
  135. cases = {}
  136. shuffle_cases()
  137. hidden_cases = dict.copy(cases)
  138. print('Choose a case #(1-25): ', end='')
  139. player_choice = input()
  140. while not player_choice.isnumeric() or not (1 <= int(player_choice) <= 25):
  141. print('Please enter a postive integer in range of 1-25')
  142. player_choice = input()
  143.  
  144. players_case = cases[int(player_choice)]
  145.  
  146. used_cases = {}
  147. used_cases[player_choice] = players_case
  148. round_counter = 1
  149.  
  150. # Number of cases to choose per round
  151. rounds = { 1:5, 2:5, 3:4, 4:2, 5:2, 6:1, 7:1, 8:1, 9:1, 10:1, 11:1}
  152. print('\n------------------------------------')
  153. print(f'\nGreat! You choose case #{player_choice}. I hope it has the 1,000,000!\n')
  154. del cases[int(player_choice)]
  155. while round_counter < len(rounds):
  156. number_of_cases_to_choose = rounds[round_counter]
  157. print_remaining_cases(cases)
  158. print_remaining_values(hidden_cases)
  159. print(f'\nIn round #{round_counter} you have to choose {number_of_cases_to_choose} cases')
  160. for i in range(1, number_of_cases_to_choose + 1):
  161. print(f'Choose case number {i}: ', end='')
  162. guess = input()
  163. while (guess in used_cases or guess == player_choice) or (not guess.isnumeric() or not (1 <= int(guess) <= 25)):
  164. while not guess.isnumeric() or not (1 <= int(guess) <= 25):
  165. print('You must enter a positive whole number between 1 and 25.')
  166. print('What case would you like to choose?: ', end='')
  167. guess = input()
  168. print(f"Case #{guess} has already been chosen. Please choose another case: ", end = '')
  169. guess = input()
  170.  
  171. used_cases[guess] = cases[int(guess)]
  172.  
  173. print(f'Case #{guess} = {cases[int(guess)]}\n')
  174. del cases[int(guess)]
  175. del hidden_cases[int(guess)]
  176.  
  177. bank_offer(cases, round_counter, players_case)
  178. print('-------------------------------------------')
  179. round_counter += 1
  180. if round_counter == len(rounds):
  181. print('\n We are down to the last two!')
  182. print('Do you want to keep your original case or switch to the remaining case?')
  183. print('Press ENTER to keep your case. Type (s)witch to switch cases.')
  184. final = input()
  185. if final == '':
  186. print(f'Congratulations! You won ${players_case}! Thank you for playing!')
  187. sys.exit()
  188. else:
  189. del hidden_cases[int(player_choice)]
  190. print_remaining_values(hidden_cases)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement