Implemented steal()-function and taking a card from card_stack

This commit is contained in:
adamercat 2021-01-11 18:04:09 +01:00
parent 323f6bce24
commit e98634d887
1 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,9 @@
"""main module"""
__author__ = ""
__credits__ = ""
__email__ = ""
import random
import clean_input
@ -12,43 +16,43 @@ def central_function():
active = 0 # contains index of the active player
card_stack, players_with_cards, players = initialize()
..., players_with_cards, players = initialize()[0], initialize()[1], initialize()[2]
while deckP1 and deckP2 and deckP3 not empty:
round(..., players_with_cards, players)
round(card_stack, players_with_cards, players, active)
# TO DO implement active_player rotation
def round(..., players_with_cards, players):
def round(card_stack, players_with_cards, players,active):
'''structures one round in the game'''
while player_request in deck_of_player:
choose(..., players_with_cards, players)
choose(card_stack, players_with_cards, players,active)
def choose(..., players_with_cards, players):
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_player)
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?'))
player_request = input('Welche Karte möchtest du haben?') # TODO: needs clean.io dict magic
'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(P1, P2)
steal(active, chosen_player)
else:
# end of round
if stack == exists:
# TODO: player.values + card_from_stack
# 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
def steal(P1, P2):
"""defines how the active players steals cards from chosen player """
# TODO: write steal function
players_with_cards[active].['cards_on_hand'].append(players_with_cards[chosen_player]['cards_on_hand'].pop(player_request))
def initialize():
"""
@ -63,7 +67,7 @@ def initialize():
x = 0
for i in range(4):
for l in "abcdefgh":
d = {"id": x, "number": i, "letter": l}
d = {"id": str(x), "number": str(i), "letter": l}
card_stack.append(d)
x += 1