Guest User

Untitled

a guest
Jan 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1. import random
  2.  
  3.  
  4.  
  5. faces = ["A", "2", "3", "4", "5", "6", "7", "8", "9",
  6. "10", "J", "Q", "K"]
  7. suits = ["s", "h", "d", "c"]
  8. cards = []
  9. playerhand = []
  10. cpuhand = []
  11. cards_used = []
  12.  
  13. player_roll = 10,000
  14. cpu_roll = 10,000
  15. pot = 0
  16.  
  17. #iterate over faces and suits to create cards and add them to cards list
  18. for i in range (0, len(faces)):
  19. for j in range (0, len(suits)):
  20. card = (faces[i]+suits[j])
  21. cards.append(card)
  22.  
  23.  
  24. #shuffle the deck with random sample
  25. deck = random.sample(cards, 52)
  26.  
  27. print(*deck, sep = "n")
  28.  
  29.  
  30. # deal a 5 card hand to player
  31. for n in range (5):
  32. player_card = random.choice(deck)
  33. playerhand.append(player_card)
  34. deck.remove(player_card)
  35. cards_used.append(player_card)
  36.  
  37. #CPU deals itself a hand
  38. for n in range (5):
  39. cpu_card = random.choice(deck)
  40. cpuhand.append(cpu_card)
  41. deck.remove(cpu_card)
  42. cards_used.append(cpu_card)
  43.  
  44.  
  45. # player sees hand for the first time
  46. print(*playerhand)
  47.  
  48. all_moves = ["check", "bet", "raise", "call", "fold"]
  49. under_the_gun = ["check", "bet"]
  50. faced_with_bet = ["call", "raise", "fold"]
  51. getting_raised = ["call", "re-raise", "fold",
  52. "reraise"]
  53.  
  54.  
  55.  
  56. #flip coin for button
  57. button = random.randint(0, 1)
  58.  
  59. #these nested if statements determines the play up until the draw
  60. if button == 0:
  61. print("CPU on the button, player 1 first to act")
  62.  
  63. while True:
  64. action = input("check or bet?")
  65. if action in under_the_gun:
  66. break
  67.  
  68. #pre-draw checking
  69. if action == "check":
  70. print("Player1 checks, action to CPU")
  71. cpu_action = random.choice(under_the_gun)
  72.  
  73. if cpu_action == "check":
  74. print("CPU checks")
  75.  
  76. #now that both player and CPU have
  77. checked, it's time for the draw
  78.  
  79. player_draw_num = int(input("How many
  80. cards to draw?"))
  81.  
  82. #player stands pat
  83. if player_draw_num == 0:
  84. print("Okay, suit yourself!")
  85. print(*playerhand)
  86.  
  87. #now the CPU gets to draw
  88. cpu_draw_num = random.randint(0,5)
  89.  
  90. if cpu_draw_num == 0:
  91. print("CPU stands pat")
  92. elif cpu_draw_num == 1:
  93. print("CPU draws 1 card")
  94. cpu_dropcard =
  95. random.choice(cpuhand)
  96. cpuhand.remove(cpu_dropcard)
  97. new_card = random.choice(deck)
  98. cpuhand.append(new_card)
  99. deck.remove(new_card)
  100.  
  101. elif cpu_draw_num == 2:
  102. print("CPU draws 2 cards")
  103. cpu_dropcard =
  104. random.choice(cpuhand)
  105. cpuhand.remove(cpu_dropcard)
  106. cpu_dropcard2 =
  107. random.choice(cpuhand)
  108. cpuhand.remove(cpu_dropcard2)
  109. new_card = random.choice(deck)
  110. cpuhand.append(new_card)
  111. deck.remove(new_card)
  112. new_card2 = random.choice(deck)
  113. cpuhand.append(new_card2)
  114. deck.remove(new_card2)
  115.  
  116. elif cpu_draw_num == 3:
  117. print("CPU draws 3 cards")
  118. cpu_dropcard =
  119. random.choice(cpuhand)
  120. cpuhand.remove(cpu_dropcard)
  121. cpu_dropcard2 = random.choice(cpuhand)
  122. cpuhand.remove(cpu_dropcard2)
  123. cpu_dropcard3 = random.choice(cpuhand)
  124. cpuhand.remove(cpu_dropcard3)
  125. new_card = random.choice(deck)
  126. cpuhand.append(new_card)
  127. deck.remove(new_card)
  128. new_card2 = random.choice(deck)
  129. cpuhand.append(new_card2)
  130. deck.remove(new_card2)
  131. new_card3 = random.choice(deck)
  132. cpuhand.append(new_card3)
  133. deck.remove(new_card3)
  134.  
  135. elif cpu_draw_num == 4:
  136. print("CPU draws 4 cards")
  137. cpu_dropcard = random.choice(cpuhand)
  138. cpuhand.remove(cpu_dropcard)
  139. cpu_dropcard2 = random.choice(cpuhand)
  140. cpuhand.remove(cpu_dropcard2)
  141. cpu_dropcard3 = random.choice(cpuhand)
  142. cpuhand.remove(cpu_dropcard3)
  143. cpu_dropcard4 = random.choice(cpuhand)
  144. cpuhand.remove(cpu_dropcard4)
  145. new_card = random.choice(deck)
  146. cpuhand.append(new_card)
  147. deck.remove(new_card)
  148. new_card2 = random.choice(deck)
  149. cpuhand.append(new_card2)
  150. deck.remove(new_card2)
  151. new_card3 = random.choice(deck)
  152. cpuhand.append(new_card3)
  153. deck.remove(new_card3)
  154. new_card4 = random.choice(deck)
  155. cpuhand.append(new_card4)
  156. deck.remove(new_card4)
  157.  
  158. else:
  159. print("CPU draws all 5")
  160. for i in len(cpuhand):
  161. cpuhand.remove(cpuhand[i])
  162. for newcard in len(cpuhand):
  163. newcard = random.choice(deck)
  164. cpuhand.append(newcard)
  165. #player has stood pat, CPU has drawn.
  166.  
  167. #action back to player1 for final bet
  168. while True:
  169. action = input("check or bet?")
  170. if action in under_the_gun:
  171. break
  172. if action == "check":
  173. print("Player_1 checks, action to
  174. CPU")
  175. cpu_action =
  176. random.choice(under_the_gun)
  177.  
  178. if cpu_action == "check":
  179. print("CPU checks as well.")
  180. print("Time for Showdown -------")
  181. print(*playerhand)
  182. print(*cpuhand)
  183. else:
  184. cpu_bet = random.randint(10,
  185. 10000)
  186. print("CPU bets", cpu_bet)
  187.  
  188. else:
  189. finalbet = int(input("How much to
  190. bet?"))
  191. print("Player bets", finalbet)
  192.  
  193.  
  194. #CPU decides whether or not to call,
  195. raise, or fold
  196.  
  197. decision =
  198. random.choice(faced_with_bet)
  199.  
  200.  
  201.  
  202.  
  203. #Player 1 checks pre-draw, CPU bets
  204. else:
  205. cpu_bet = random.randint(10, 10000)
  206. print("CPU bets", cpu_bet)
  207. pot = cpu_bet
  208. cpu_roll = cpu_roll - cpu_bet
  209.  
  210. #action back to player 1
  211. while True:
  212. action = input("Call, raise, or fold?")
  213. if action not in faced_with_bet:
  214. break
  215. if action == "call":
  216. print("Player1 calls", cpu_bet)
  217. pot = pot + cpu_bet
  218. player_roll = player_roll - call
  219. elif action == "raise":
  220. while True:
  221. raise_amount = input("How much do you
  222. want to raise by?")
  223. if raise_amount < player_roll:
  224. break
  225. print("Player 1 raises", raise_amount)
  226. pot = pot + raise_amount
  227. player_roll = player_roll - raise_amount
  228.  
  229. #else player 1 folds
  230. else:
  231. print("Player1 folds, CPU takes pot of",
  232. pot)
  233. cpu_roll = cpu_roll + pot
  234. print("CPU cash:$ ", cpu_roll)
  235. print("Player 1 cash: $ ", player_roll)
  236.  
  237. good
  238.  
  239.  
  240. #else player 1 wants to bet (pre-draw still)
  241. else:
  242.  
  243. bet = int(input("How much would you like to
  244. bet?"))
  245. print("Player bets", bet)
  246. player_roll = player_roll - bet
  247. pot = pot + bet
  248.  
  249. #CPU has to decide whether to call, raise, or fold
  250. decision = random.choice(faced_with_bet)
  251.  
  252. if decision == "call":
  253. print("CPU calls", bet)
  254. cpu_roll = cpu_roll - bet
  255. pot = pot + bet
  256. print("Pot size: ", pot)
  257. elif decision == "raise":
  258. raise_factor = random.randint(2,5)
  259. cpu_raise = ((bet * raise_factor) - bet)
  260. cpu_roll = cpu_roll - cpu_raise - bet
  261. pot = pot + cpu_raise + bet
  262. print ("CPU raises", cpu_raise)
  263. print("Pot size: ", pot)
  264.  
  265. #now player 1 needs to decide whether to call, re-raise, or fold:
  266. while True:
  267. raisedchoice = input("call, fold, or re-raise?")
  268. if raisedchoice in getting_raised:
  269. break
  270. if raised_choice == "call":
  271. player_roll = player_roll - cpu_raise
  272. pot = pot + cpu_raise
  273. print("Player1 calls, time for showdown!")
  274. print(*playerhand)
  275. print(*cpuhand)
  276. else:
  277. print("Not there yet")
  278.  
  279. else:
  280. print("You're on the button, action to CPU")
  281.  
  282. cpu_action = random.choice(under_the_gun)
  283. if cpu_action == "bet":
  284. bet = random.randint(10, 10000)
  285. print("CPU bets", bet)
  286.  
  287. else:
  288. print("CPU checks")
Add Comment
Please, Sign In to add comment