Implement card removal functionality and update player 1's hand management
This commit is contained in:
parent
4a36bfdfca
commit
c2d5d799fc
20
poker.py
20
poker.py
@ -42,6 +42,12 @@ def hand_rank(hand):
|
|||||||
def show_hand(hand):
|
def show_hand(hand):
|
||||||
return '\n '.join([f"{rank} of {suit}" for rank, suit in hand])
|
return '\n '.join([f"{rank} of {suit}" for rank, suit in hand])
|
||||||
|
|
||||||
|
def remove_card_from_hand(hand, card):
|
||||||
|
if card in hand:
|
||||||
|
hand.remove(card)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
deck = create_deck()
|
deck = create_deck()
|
||||||
random.shuffle(deck)
|
random.shuffle(deck)
|
||||||
@ -50,7 +56,18 @@ def main():
|
|||||||
print("Player 1's hand:\n", show_hand(player1))
|
print("Player 1's hand:\n", show_hand(player1))
|
||||||
print()
|
print()
|
||||||
print("Player 2's hand:\n", show_hand(player2))
|
print("Player 2's hand:\n", show_hand(player2))
|
||||||
rank1 = hand_rank(player1)
|
|
||||||
|
|
||||||
|
pull_card_player1 = input("Player 1, enter a card to pull from your hand (e.g., 'A of Spades', or 'none'): ")
|
||||||
|
if 'none' not in pull_card_player1.lower():
|
||||||
|
rank, suit = pull_card_player1.split(' of ')
|
||||||
|
if remove_card_from_hand(player1, (rank, suit)):
|
||||||
|
player1.remove((rank, suit))
|
||||||
|
print("Player 1 pulled", rank, "of", suit, "from his hand.")
|
||||||
|
else:
|
||||||
|
print("Card not found in Player 1's hand.")
|
||||||
|
|
||||||
|
rank1 = hand_rank(player1)
|
||||||
rank2 = hand_rank(player2)
|
rank2 = hand_rank(player2)
|
||||||
if rank1 > rank2:
|
if rank1 > rank2:
|
||||||
print("Player 1 wins! with rank:", rank1)
|
print("Player 1 wins! with rank:", rank1)
|
||||||
@ -62,5 +79,6 @@ def main():
|
|||||||
print("It's a tie!")
|
print("It's a tie!")
|
||||||
print("Both players have rank:", rank1)
|
print("Both players have rank:", rank1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user