From a4f7c922b1f56b4de899462db472a14d9a75fa1b Mon Sep 17 00:00:00 2001 From: Jonas_Jones <91549607+J-onasJones@users.noreply.github.com> Date: Thu, 22 Dec 2022 16:01:07 +0100 Subject: [PATCH] added compare_cards() --- game.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/game.py b/game.py index 75f2372..d4f6ca4 100644 --- a/game.py +++ b/game.py @@ -1,15 +1,15 @@ __author__ = "7987847, Werner, 7347119, Fajst, 1234567, dalimeli" +RANKS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'] +SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] + def create_cards(): - ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', - 'Queen', 'King'] - suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] card_deck = [] - for suit in suits: - for rank in ranks: - card = f'{rank} of {suit}' + for suit in SUITS: + for rank in RANKS: + card = {'rank': rank, 'suit': suit} card_deck.append(card) return card_deck @@ -40,6 +40,30 @@ def deal_cards(card_deck:list, players:int, cards_per_player:int): return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3], temp_cards[4]) +def compare_cards(cards_to_compare:list): + ''' + Compares the given cards and returns the winner + + input: + - cards_to_compare: list + list of cards to compare + output: + - winner: int + index of the winning card + ''' + winner = 0 + # TODO: wtf is Trumpffarbe? help + # Trumpffarbe-condition muss auch noch implementiert werden + for i in range(1, len(cards_to_compare)): + if RANKS.index(cards_to_compare[i]['rank']) > RANKS.index(cards_to_compare[winner]['rank']): + winner = i + if RANKS.index(cards_to_compare[i]['rank']) == RANKS.index(cards_to_compare[winner]['rank']): + if SUITS.index(cards_to_compare[i]['suit']) > SUITS.index(cards_to_compare[winner]['suit']): + winner = i + return winner + + + card_deck = create_cards() print(card_deck)