diff --git a/game.py b/game.py index c025431..aecf81b 100644 --- a/game.py +++ b/game.py @@ -39,15 +39,21 @@ def deal_cards(card_deck:list, players:int, cards_per_player:int): - player_cards: tuple tuple of lists, each list contains the cards of a player ''' + # create a list of lists, each list contains the cards of a player in the + # order of their occurance in the players list in the game loop of main.py temp_cards = [] for player in range(players): temp_cards.append([]) for _ in range(cards_per_player): + # add a random card to the player's list and remove it from the + # deck temp_cards[player].append(card_deck.pop(randint(0, len(card_deck)-1))) + # if the number of players is not equal to 5, add empty lists to the list + # until it has 5 elements while len(temp_cards) < 5: temp_cards.append([]) - + # return the list of lists as a tuple return (temp_cards[0], temp_cards[1], temp_cards[2], temp_cards[3], temp_cards[4]) @@ -63,22 +69,33 @@ def compare_cards(cards_to_compare:list, trumpf_color:str): - winner: int index of the winning card ''' + # first player is defined as winner winner = 0 + # no possible trump card has been detected yet + # list contains all indices of trump cards + # index maps to index in cards_to_compare trumpf = [] + # index of all trump cards are added to trumpf for i in cards_to_compare: if i.get('suit') == trumpf_color: trumpf.append(cards_to_compare.index(i)) if len(trumpf) == 1: + # if only one trump card is present, it is the winner return trumpf[0] elif len(trumpf) > 1: winner = 0 for j in trumpf: + # loop through all trump cards and compare them + # highest rank is the winner if RANKS.index(cards_to_compare[j].get('rank')) > RANKS.index( cards_to_compare[winner].get('rank')): winner = j winner = j else: + # no trump card is present winner = 0 + # loop through all cards and compare them + # highest rank is the winner for j in cards_to_compare: if RANKS.index(j.get('rank')) > RANKS.index( cards_to_compare[winner].get('rank')):