From e728d88f298e5747c6b56d740c21d39ab3205a88 Mon Sep 17 00:00:00 2001 From: NathanKim16 Date: Tue, 17 Feb 2026 18:57:48 -0500 Subject: [PATCH] Fix to Issue #163 --- casino/games/uno/player.py | 34 ++++++++++++++++++++++++++++++---- casino/games/uno/uno.py | 27 ++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/casino/games/uno/player.py b/casino/games/uno/player.py index 0de6e47..c7ecae7 100644 --- a/casino/games/uno/player.py +++ b/casino/games/uno/player.py @@ -7,17 +7,43 @@ def __init__(self, id, name) : self.id = id self.name = name.upper() self.hand = [] + + #Stats + self.cards_played = 0 + self.draws_taken = 0 + self.wilds_played = 0 + self.draw2_played = 0 + self.draw4_played = 0 + self.skips_played = 0 + self.reverses_played = 0 def draw(self, deck: list[UnoCard]) -> UnoCard: c = random.choice(deck) self.hand.append(c) deck.remove(c) + #Track the draws taken + self.draws_taken += 1 return c - def play_card(self) -> UnoCard: - c = random.choice(self.hand) - self.hand.remove(c) - return c + def play_card(self, card:UnoCard) -> UnoCard: + self.hand.remove(card) + #Track the cards played + self.cards_played += 1 + + #Add action to stats + if card.color == "wild": + if card.rank == "wild_draw_4": + self.draw4_played += 1 + else: + self.wilds_played += 1 + elif card.rank == "draw_2": + self.draw2_played += 1 + elif card.rank == "skip": + self.skips_played += 1 + elif card.rank == "reverse": + self.reverses_played += 1 + + return card def playable_cards(self, currentCard : UnoCard) -> list[UnoCard]: valid_cards = [] diff --git a/casino/games/uno/uno.py b/casino/games/uno/uno.py index 521f980..97c898e 100644 --- a/casino/games/uno/uno.py +++ b/casino/games/uno/uno.py @@ -96,6 +96,8 @@ def play_uno(ctx: GameContext) -> None: continueGame = True currentPlayerIndex = 0 direction = 1 + winner = None + while(continueGame) : i = players[currentPlayerIndex] current_card = discard[-1] @@ -116,6 +118,8 @@ def play_uno(ctx: GameContext) -> None: if (answer == "d" or answer == "draw") : new_card = i.draw(current_deck) cprint("You drew \n" + str(new_card) + " from the pile.") + i.draws_taken += 1 + elif (answer == "p" or answer == "play") : VALID_COLORS = ["red", "green", "blue", "yellow"] VALID_RANKS = [str(n) for n in range(0, 10)] + ["draw_2", "skip", "reverse"] @@ -155,14 +159,35 @@ def play_uno(ctx: GameContext) -> None: answer = cinput(INVALID_CARD_MSG).lower() if (answer == "draw" or answer == "d"): new_card = i.draw(current_deck) + i.draws_taken += 1 cprint("You drew \n" + str(new_card) + " from the pile.") break + #If actual valid card is chosen + if valid_card: + i.hand.remove(new_card) + i.cards_played += 1 + + if new_card.color == "wild": + if new_card.rank == "wild_draw_4": + i.draw4_played += 1 + else: + i.wilds_played += 1 - i.hand.remove(new_card) + # i.hand.remove(new_card) if len(i.hand) == 0: continueGame = False + winner = i display_uno_topbar(ctx) cprint(f"{i.name} is the winner!") + cprint("\n" + "═"*34) + cprint(" FINAL STATISTICS") + cprint("═"*34) + cprint(f"{'Player':<12} Cards left Played Draws Wild +4") + cprint("-"*50) + for p in players: + left = len(p.hand) + cprint(f"{p.name:<12} {left:>9} {p.cards_played:>5} {p.draws_taken:>5} {p.wilds_played:>4} {p.draw4_played:>3}") + cprint("═"*50 + "\n") cinput("Press enter when ready to exit") break match new_card.rank: