Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- faces = ["A", "2", "3", "4", "5", "6", "7", "8", "9",
- "10", "J", "Q", "K"]
- suits = ["s", "h", "d", "c"]
- cards = []
- playerhand = []
- cpuhand = []
- cards_used = []
- player_roll = 10,000
- cpu_roll = 10,000
- pot = 0
- #iterate over faces and suits to create cards and add them to cards list
- for i in range (0, len(faces)):
- for j in range (0, len(suits)):
- card = (faces[i]+suits[j])
- cards.append(card)
- #shuffle the deck with random sample
- deck = random.sample(cards, 52)
- print(*deck, sep = "n")
- # deal a 5 card hand to player
- for n in range (5):
- player_card = random.choice(deck)
- playerhand.append(player_card)
- deck.remove(player_card)
- cards_used.append(player_card)
- #CPU deals itself a hand
- for n in range (5):
- cpu_card = random.choice(deck)
- cpuhand.append(cpu_card)
- deck.remove(cpu_card)
- cards_used.append(cpu_card)
- # player sees hand for the first time
- print(*playerhand)
- all_moves = ["check", "bet", "raise", "call", "fold"]
- under_the_gun = ["check", "bet"]
- faced_with_bet = ["call", "raise", "fold"]
- getting_raised = ["call", "re-raise", "fold",
- "reraise"]
- #flip coin for button
- button = random.randint(0, 1)
- #these nested if statements determines the play up until the draw
- if button == 0:
- print("CPU on the button, player 1 first to act")
- while True:
- action = input("check or bet?")
- if action in under_the_gun:
- break
- #pre-draw checking
- if action == "check":
- print("Player1 checks, action to CPU")
- cpu_action = random.choice(under_the_gun)
- if cpu_action == "check":
- print("CPU checks")
- #now that both player and CPU have
- checked, it's time for the draw
- player_draw_num = int(input("How many
- cards to draw?"))
- #player stands pat
- if player_draw_num == 0:
- print("Okay, suit yourself!")
- print(*playerhand)
- #now the CPU gets to draw
- cpu_draw_num = random.randint(0,5)
- if cpu_draw_num == 0:
- print("CPU stands pat")
- elif cpu_draw_num == 1:
- print("CPU draws 1 card")
- cpu_dropcard =
- random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard)
- new_card = random.choice(deck)
- cpuhand.append(new_card)
- deck.remove(new_card)
- elif cpu_draw_num == 2:
- print("CPU draws 2 cards")
- cpu_dropcard =
- random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard)
- cpu_dropcard2 =
- random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard2)
- new_card = random.choice(deck)
- cpuhand.append(new_card)
- deck.remove(new_card)
- new_card2 = random.choice(deck)
- cpuhand.append(new_card2)
- deck.remove(new_card2)
- elif cpu_draw_num == 3:
- print("CPU draws 3 cards")
- cpu_dropcard =
- random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard)
- cpu_dropcard2 = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard2)
- cpu_dropcard3 = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard3)
- new_card = random.choice(deck)
- cpuhand.append(new_card)
- deck.remove(new_card)
- new_card2 = random.choice(deck)
- cpuhand.append(new_card2)
- deck.remove(new_card2)
- new_card3 = random.choice(deck)
- cpuhand.append(new_card3)
- deck.remove(new_card3)
- elif cpu_draw_num == 4:
- print("CPU draws 4 cards")
- cpu_dropcard = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard)
- cpu_dropcard2 = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard2)
- cpu_dropcard3 = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard3)
- cpu_dropcard4 = random.choice(cpuhand)
- cpuhand.remove(cpu_dropcard4)
- new_card = random.choice(deck)
- cpuhand.append(new_card)
- deck.remove(new_card)
- new_card2 = random.choice(deck)
- cpuhand.append(new_card2)
- deck.remove(new_card2)
- new_card3 = random.choice(deck)
- cpuhand.append(new_card3)
- deck.remove(new_card3)
- new_card4 = random.choice(deck)
- cpuhand.append(new_card4)
- deck.remove(new_card4)
- else:
- print("CPU draws all 5")
- for i in len(cpuhand):
- cpuhand.remove(cpuhand[i])
- for newcard in len(cpuhand):
- newcard = random.choice(deck)
- cpuhand.append(newcard)
- #player has stood pat, CPU has drawn.
- #action back to player1 for final bet
- while True:
- action = input("check or bet?")
- if action in under_the_gun:
- break
- if action == "check":
- print("Player_1 checks, action to
- CPU")
- cpu_action =
- random.choice(under_the_gun)
- if cpu_action == "check":
- print("CPU checks as well.")
- print("Time for Showdown -------")
- print(*playerhand)
- print(*cpuhand)
- else:
- cpu_bet = random.randint(10,
- 10000)
- print("CPU bets", cpu_bet)
- else:
- finalbet = int(input("How much to
- bet?"))
- print("Player bets", finalbet)
- #CPU decides whether or not to call,
- raise, or fold
- decision =
- random.choice(faced_with_bet)
- #Player 1 checks pre-draw, CPU bets
- else:
- cpu_bet = random.randint(10, 10000)
- print("CPU bets", cpu_bet)
- pot = cpu_bet
- cpu_roll = cpu_roll - cpu_bet
- #action back to player 1
- while True:
- action = input("Call, raise, or fold?")
- if action not in faced_with_bet:
- break
- if action == "call":
- print("Player1 calls", cpu_bet)
- pot = pot + cpu_bet
- player_roll = player_roll - call
- elif action == "raise":
- while True:
- raise_amount = input("How much do you
- want to raise by?")
- if raise_amount < player_roll:
- break
- print("Player 1 raises", raise_amount)
- pot = pot + raise_amount
- player_roll = player_roll - raise_amount
- #else player 1 folds
- else:
- print("Player1 folds, CPU takes pot of",
- pot)
- cpu_roll = cpu_roll + pot
- print("CPU cash:$ ", cpu_roll)
- print("Player 1 cash: $ ", player_roll)
- good
- #else player 1 wants to bet (pre-draw still)
- else:
- bet = int(input("How much would you like to
- bet?"))
- print("Player bets", bet)
- player_roll = player_roll - bet
- pot = pot + bet
- #CPU has to decide whether to call, raise, or fold
- decision = random.choice(faced_with_bet)
- if decision == "call":
- print("CPU calls", bet)
- cpu_roll = cpu_roll - bet
- pot = pot + bet
- print("Pot size: ", pot)
- elif decision == "raise":
- raise_factor = random.randint(2,5)
- cpu_raise = ((bet * raise_factor) - bet)
- cpu_roll = cpu_roll - cpu_raise - bet
- pot = pot + cpu_raise + bet
- print ("CPU raises", cpu_raise)
- print("Pot size: ", pot)
- #now player 1 needs to decide whether to call, re-raise, or fold:
- while True:
- raisedchoice = input("call, fold, or re-raise?")
- if raisedchoice in getting_raised:
- break
- if raised_choice == "call":
- player_roll = player_roll - cpu_raise
- pot = pot + cpu_raise
- print("Player1 calls, time for showdown!")
- print(*playerhand)
- print(*cpuhand)
- else:
- print("Not there yet")
- else:
- print("You're on the button, action to CPU")
- cpu_action = random.choice(under_the_gun)
- if cpu_action == "bet":
- bet = random.randint(10, 10000)
- print("CPU bets", bet)
- else:
- print("CPU checks")
Add Comment
Please, Sign In to add comment