diff --git a/quartett.py b/quartett.py index b5aa1ab..2473250 100644 --- a/quartett.py +++ b/quartett.py @@ -7,19 +7,25 @@ __email__ = "" import random import clean_input import itertools - +import copy # Game def central_function(): - ''' does everything, keeps order''' + ''' + does everything, keeps order + ''' active = 0 # contains index of the active player switch = True card_stack, players_with_cards, players = initialize() - print(players) + print("players",players) # debug + print("card stack", card_stack) # debug + for i in range(len(players)): # debug + pretty_print_deck(players_with_cards, i) # debug + print("active", active) # debug drop_cards(players_with_cards) while switch: round(card_stack, players_with_cards, players, active) @@ -27,8 +33,8 @@ def central_function(): for i in range(len(players)): # check if any card deck is empty switch = bool(players_with_cards[i]['cards_on_hand']) - for i in itertools.cycle(range(len(players))): # rotate active player - active = i + #for i in itertools.cycle(range(len(players))): # rotate active player + # active = i # the_winner_is() @@ -42,37 +48,50 @@ def round(card_stack, players_with_cards, players, active): switch = True while switch: - players_without_active = players - players_without_active.remove(active) + players_without_active = copy.copy(players) + players_without_active.pop(active) print('Folgende Spieler stehen zur Verfügung:') print(players_without_active) - # needs clean.io, chosen_player enthält den index in der players liste - chosen_player = clean_input.io_str('Welchen Spieler möchtest du befragen?', - players_without_active) - player_request = clean_input.io_card_selection('Welche Karte möchtest du haben?') + # chosen_player enthält den index in der players liste + chosen_player = players.index(clean_input.io_str( + 'Welchen Spieler möchtest du befragen? ', players_without_active)) + print("chosen player", chosen_player) + player_request = clean_input.io_card_selection('Welche Karte möchtest du haben? ') if player_request in players_with_cards[chosen_player]['cards_on_hand']: steal(active, chosen_player, players_with_cards, player_request) drop_cards(players_with_cards, active) else: + print("Diese Karte hat der Spieler nicht, Ende der Runde") # end of round - # except if stack is not empty, which is only the case with two players + # except if stack is not empty, which is not only the case with two players if card_stack == True: # last card from the stack gets added to active player's hand players_with_cards[active]['cards_on_hand'].append(card_stack.pop()) switch = False +def pretty_print_deck(players_with_cards, player): + """ + prints the cards in a players deck in a readable format + """ + + pretty_deck = [] + for card in players_with_cards[player]['cards_on_hand']: + pretty_deck.append(card['number'] + card['letter']) + print("Dein Deck: ", pretty_deck) def steal(active, chosen_player, players_with_cards, player_request): """ defines how the active players steals cards from chosen player :return: None """ - + print("player", chosen_player, "hat die Karte, die du haben möchtest und sie wandert in dein Deck.") + card_index = players_with_cards[chosen_player]['cards_on_hand'].index(player_request) players_with_cards[active]['cards_on_hand'].append( - players_with_cards[chosen_player]['cards_on_hand'].pop(player_request)) + players_with_cards[chosen_player]['cards_on_hand'].pop(card_index)) + pretty_print_deck(players_with_cards, active) def drop_cards(players_with_cards, active=None): @@ -173,7 +192,9 @@ def the_winner_is(): # Call central_function() only if quartett.py is the main module if __name__ == "__main__": - p = {'player': 'player1', 'cards_on_hand': [{'id': '27', 'number': '3', 'letter': 'd'}, + central_function() + +"""p = {'player': 'player1', 'cards_on_hand': [{'id': '27', 'number': '3', 'letter': 'd'}, {'id': '3', 'number': '0', 'letter': 'd'}, {'id': '25', 'number': '3', 'letter': 'd'}, {'id': '19', 'number': '2', 'letter': 'd'}, @@ -184,8 +205,8 @@ if __name__ == "__main__": {'id': '9', 'number': '1', 'letter': 'b'}, {'id': '7', 'number': '0', 'letter': 'h'}], 'quartet': 0} - drop_cards_help(p) - # central_function() + drop_cards_help(p)""" + ''' players_with_cards = [