2021-01-06 16:57:51 +01:00
|
|
|
"""main module"""
|
|
|
|
|
2021-01-11 18:04:09 +01:00
|
|
|
__author__ = ""
|
|
|
|
__credits__ = ""
|
|
|
|
__email__ = ""
|
|
|
|
|
2021-01-06 16:57:51 +01:00
|
|
|
import random
|
|
|
|
import clean_input
|
2021-01-12 10:41:48 +01:00
|
|
|
#import itertools
|
2021-01-06 16:57:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Game
|
|
|
|
|
|
|
|
def central_function():
|
|
|
|
''' does everything, keeps order'''
|
|
|
|
|
|
|
|
active = 0 # contains index of the active player
|
|
|
|
|
2021-01-11 16:49:05 +01:00
|
|
|
card_stack, players_with_cards, players = initialize()
|
2021-01-12 10:41:48 +01:00
|
|
|
print(players)
|
|
|
|
# while deckP1 and deckP2 and deckP3 not empty:
|
|
|
|
# round(card_stack, players_with_cards, players, active)
|
|
|
|
# for i in itertools.cycle(range(len(players))):
|
|
|
|
# active = i
|
2021-01-06 16:57:51 +01:00
|
|
|
|
|
|
|
|
2021-01-12 10:41:48 +01:00
|
|
|
def round(card_stack, players_with_cards, players, active):
|
2021-01-11 18:40:12 +01:00
|
|
|
'''structures one round in the game
|
|
|
|
active player chooses another player from whom to steal a card'''
|
2021-01-12 10:41:48 +01:00
|
|
|
|
2021-01-11 18:40:12 +01:00
|
|
|
switch = True
|
|
|
|
|
2021-01-12 10:41:48 +01:00
|
|
|
while switch:
|
2021-01-11 18:40:12 +01:00
|
|
|
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
|
2021-01-12 10:41:48 +01:00
|
|
|
chosen_player = clean_input.io_str('Welchen Spieler möchtest du befragen?',
|
|
|
|
players_without_active)
|
2021-01-11 18:40:12 +01:00
|
|
|
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']:
|
2021-01-12 10:41:48 +01:00
|
|
|
steal(active, chosen_player, players_with_cards, player_request)
|
2021-01-11 18:40:12 +01:00
|
|
|
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())
|
2021-01-12 10:41:48 +01:00
|
|
|
|
2021-01-11 18:40:12 +01:00
|
|
|
switch = False
|
2021-01-06 16:57:51 +01:00
|
|
|
|
|
|
|
|
2021-01-12 10:41:48 +01:00
|
|
|
def steal(active, chosen_player, players_with_cards, player_request):
|
2021-01-06 16:57:51 +01:00
|
|
|
"""defines how the active players steals cards from chosen player """
|
2021-01-12 10:41:48 +01:00
|
|
|
players_with_cards[active]['cards_on_hand'].append(
|
|
|
|
players_with_cards[chosen_player]['cards_on_hand'].pop(player_request))
|
|
|
|
|
2021-01-06 16:57:51 +01:00
|
|
|
|
|
|
|
def initialize():
|
|
|
|
"""
|
|
|
|
initializes stuff
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
2021-01-11 16:49:05 +01:00
|
|
|
card_stack = []
|
2021-01-06 16:57:51 +01:00
|
|
|
players = []
|
|
|
|
players_with_cards = []
|
|
|
|
|
|
|
|
x = 0
|
|
|
|
for i in range(4):
|
|
|
|
for l in "abcdefgh":
|
2021-01-11 18:04:09 +01:00
|
|
|
d = {"id": str(x), "number": str(i), "letter": l}
|
2021-01-11 16:49:05 +01:00
|
|
|
card_stack.append(d)
|
2021-01-06 16:57:51 +01:00
|
|
|
x += 1
|
|
|
|
|
2021-01-12 10:41:48 +01:00
|
|
|
number_of_players = clean_input.io_int("Gegen wie viele Spieler wollen Sie spielen?")
|
2021-01-06 16:57:51 +01:00
|
|
|
number_of_players += 1 # Add also human player.
|
|
|
|
|
|
|
|
for i in range(number_of_players):
|
|
|
|
players.append(f"player{i}")
|
|
|
|
|
|
|
|
if len(players) == 2:
|
|
|
|
cards_per_player = 10
|
|
|
|
else:
|
2021-01-11 16:49:05 +01:00
|
|
|
cards_per_player = int(len(card_stack) // len(players))
|
2021-01-06 16:57:51 +01:00
|
|
|
|
|
|
|
for i in range(number_of_players): # Select cards for x players
|
|
|
|
cards_of_player = [] # Player deck
|
|
|
|
for j in range(cards_per_player): # Select ten cards
|
2021-01-11 16:49:05 +01:00
|
|
|
x = random.randint(0, len(card_stack) - 1) # Select one random card
|
|
|
|
selected_card = card_stack[x]
|
|
|
|
del card_stack[x] # Remove card from main card deck.
|
2021-01-06 16:57:51 +01:00
|
|
|
cards_of_player.append(selected_card)
|
|
|
|
|
|
|
|
# Add list of dicts (cards) to players
|
|
|
|
players_with_cards.append({"player": players[i], "cards_on_hand": cards_of_player})
|
|
|
|
|
2021-01-11 16:49:05 +01:00
|
|
|
return card_stack, players_with_cards, players
|
2021-01-06 17:12:36 +01:00
|
|
|
|
2021-01-12 10:41:48 +01:00
|
|
|
|
|
|
|
# Call central_function() only if quartett.py is the main module
|
|
|
|
if __name__ == "__main__":
|
|
|
|
central_function()
|
|
|
|
|
2021-01-06 17:12:36 +01:00
|
|
|
'''
|
|
|
|
players_with_cards = [
|
|
|
|
{'player': 'player0', 'cards_on_hand': [{'id': 13, 'number': 1, 'letter': 'f'},
|
|
|
|
{'id': 26, 'number': 3, 'letter': 'c'},
|
|
|
|
{'id': 22, 'number': 2, 'letter': 'g'},
|
|
|
|
{'id': 10, 'number': 1, 'letter': 'c'},
|
|
|
|
{'id': 19, 'number': 2, 'letter': 'd'},
|
|
|
|
{'id': 31, 'number': 3, 'letter': 'h'},
|
|
|
|
{'id': 6, 'number': 0, 'letter': 'g'},
|
|
|
|
{'id': 9, 'number': 1, 'letter': 'b'},
|
|
|
|
{'id': 5, 'number': 0, 'letter': 'f'},
|
|
|
|
{'id': 15, 'number': 1, 'letter': 'h'}]
|
|
|
|
},
|
|
|
|
...]'''
|