implemented active rotation, fixed some assignments, implemented switch in round()

This commit is contained in:
adamercat 2021-01-11 18:40:12 +01:00
parent e98634d887
commit b9a2767eeb
1 changed files with 25 additions and 25 deletions

View File

@ -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):