Add functionality to let each player pull up to 3 cards from their hand and replace them with new cards from the deck.
This commit is contained in:
parent
02d551de2a
commit
7e58d59ebe
18
poker.py
18
poker.py
@ -12,14 +12,14 @@ player1: Hand
|
||||
player2: Hand
|
||||
deck: Deck
|
||||
|
||||
def create_deck():
|
||||
def create_deck() -> Deck:
|
||||
deck: Deck = [(rank, suit) for suit in SUITS for rank in RANKS]
|
||||
return deck
|
||||
|
||||
def deal_card(deck):
|
||||
def deal_card(deck) -> Card:
|
||||
return deck.pop()
|
||||
|
||||
def deal_hand(deck, num=5):
|
||||
def deal_hand(deck, num=5) -> Hand:
|
||||
hand = random.sample(deck, num)
|
||||
for card in hand:
|
||||
deck.remove(card)
|
||||
@ -90,7 +90,7 @@ def display_initial_hands(player1: Hand, player2: Hand):
|
||||
print("Player 2\n", show_hand(player2))
|
||||
print()
|
||||
|
||||
def display_hands(player1, player2):
|
||||
def display_hands(player1: Hand, player2: Hand):
|
||||
print("\nAfter pulling cards:")
|
||||
print("Player 1's hand:\n", show_hand(player1))
|
||||
print()
|
||||
@ -103,8 +103,14 @@ def main():
|
||||
player1 = deal_hand(deck)
|
||||
player2 = deal_hand(deck)
|
||||
display_initial_hands(player1, player2)
|
||||
handle_player_input(player1)
|
||||
handle_player_input(player2)
|
||||
print("Player 1's turn to pull a card.")
|
||||
p1_num = int(input("How many cards do you want to pull? (0-3): "))
|
||||
for _ in range(p1_num):
|
||||
handle_player_input(player1)
|
||||
print("Player 2's turn to pull a card.")
|
||||
p2_num = int(input("How many cards do you want to pull? (0-3): "))
|
||||
for _ in range(p2_num):
|
||||
handle_player_input(player2)
|
||||
display_hands(player1, player2)
|
||||
|
||||
# Evaluate hands and determine winner
|
||||
|
||||
Loading…
Reference in New Issue
Block a user