From b9a2767eebbef6f4de3e43fd42260437d2745907 Mon Sep 17 00:00:00 2001 From: adamercat Date: Mon, 11 Jan 2021 18:40:12 +0100 Subject: [PATCH] implemented active rotation, fixed some assignments, implemented switch in round() --- quartett.py | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/quartett.py b/quartett.py index dc3dc36..b12c748 100644 --- a/quartett.py +++ b/quartett.py @@ -6,6 +6,7 @@ __email__ = "" import random import clean_input +import itertools # Game @@ -18,36 +19,35 @@ def central_function(): card_stack, players_with_cards, players = initialize() while deckP1 and deckP2 and deckP3 not empty: round(card_stack, players_with_cards, players, active) - # TO DO implement active_player rotation + for i in itertools.cycle(range(len(players))): + active = i def round(card_stack, players_with_cards, players,active): - '''structures one round in the game''' + '''structures one round in the game + active player chooses another player from whom to steal a card''' + + switch = True - while player_request in deck_of_player: - choose(card_stack, players_with_cards, players,active) + while switch: + players_without_active = players + players_without_active.remove(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 = players.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?') - -def choose(card_stack, players_with_cards, players,active): - """active player chooses another player from whom to steal a card""" - - players_without_active = players.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 = players.index(input( - 'Welchen Spieler möchtest du befragen?')) # TODO needs clean io - player_request = input('Welche Karte möchtest du haben?') - - if player_request in players_with_cards[chosen_player]['cards_on_hand']: - steal(active, chosen_player) - else: - # TODO end of round - # except if stack is not empty, which is 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()) - break + if player_request in players_with_cards[chosen_player]['cards_on_hand']: + steal(active, chosen_player) + else: + # end of round + # except if stack is not empty, which is 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()) + break + switch = False def steal(P1, P2):