modified drop_cards_help()
This commit is contained in:
parent
9b628e5917
commit
4484a60f26
55
quartett.py
55
quartett.py
|
@ -6,7 +6,7 @@ __email__ = ""
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import clean_input
|
import clean_input
|
||||||
#import itertools
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
# Game
|
# Game
|
||||||
|
@ -16,6 +16,8 @@ def central_function():
|
||||||
|
|
||||||
active = 0 # contains index of the active player
|
active = 0 # contains index of the active player
|
||||||
|
|
||||||
|
switch = True
|
||||||
|
|
||||||
card_stack, players_with_cards, players = initialize()
|
card_stack, players_with_cards, players = initialize()
|
||||||
print(players)
|
print(players)
|
||||||
drop_cards(players_with_cards)
|
drop_cards(players_with_cards)
|
||||||
|
@ -27,7 +29,7 @@ def central_function():
|
||||||
|
|
||||||
for i in itertools.cycle(range(len(players))): # rotate active player
|
for i in itertools.cycle(range(len(players))): # rotate active player
|
||||||
active = i
|
active = i
|
||||||
#the_winner_is()
|
# the_winner_is()
|
||||||
|
|
||||||
|
|
||||||
def round(card_stack, players_with_cards, players, active):
|
def round(card_stack, players_with_cards, players, active):
|
||||||
|
@ -72,27 +74,29 @@ def steal(active, chosen_player, players_with_cards, player_request):
|
||||||
players_with_cards[active]['cards_on_hand'].append(
|
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(player_request))
|
||||||
|
|
||||||
def drop_cards(players_with_cards, active = None):
|
|
||||||
|
def drop_cards(players_with_cards, active=None):
|
||||||
"""
|
"""
|
||||||
function that lets players drop cards
|
function that lets players drop cards
|
||||||
if they have a quartet in their deck
|
if they have a quartet in their deck
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#default, check all players
|
# default, check all players
|
||||||
if active is None:
|
if active is None:
|
||||||
for p in players_with cards:
|
for p in players_with_cards:
|
||||||
drop_cards_help(p)
|
drop_cards_help(p)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
p = players_with_cards[active]
|
p = players_with_cards[active]
|
||||||
drop_cards_help(p)
|
drop_cards_help(p)
|
||||||
|
|
||||||
def drop_cards_help(players_with_cards,p):
|
|
||||||
|
def drop_cards_help(p):
|
||||||
"""
|
"""
|
||||||
eh
|
eh
|
||||||
"""
|
"""
|
||||||
reference = ['a','b','c','d','e','f','g','h']
|
reference = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
|
||||||
counter = [0, 0, 0, 0, 0, 0, 0, 0]
|
counter = [0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
|
||||||
for card in p["cards_on_hand"]:
|
for card in p["cards_on_hand"]:
|
||||||
|
@ -100,10 +104,15 @@ def drop_cards_help(players_with_cards,p):
|
||||||
|
|
||||||
for i in counter:
|
for i in counter:
|
||||||
if i == 4:
|
if i == 4:
|
||||||
quartet_letter = reference[index(i)]
|
quartet_letter = reference[counter.index(i)]
|
||||||
for card in p["cards_on_hand"]:
|
counter[counter.index(i)] = 0
|
||||||
if card["letter"] == quartet_letter:
|
p["quartet"] += 1
|
||||||
del card
|
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
|
||||||
|
p["cards_on_hand"] = [c for c in p["cards_on_hand"] if quartet_letter != c["letter"]]
|
||||||
|
|
||||||
|
# print(p)
|
||||||
|
return p
|
||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize():
|
||||||
"""
|
"""
|
||||||
|
@ -146,21 +155,37 @@ def initialize():
|
||||||
cards_of_player.append(selected_card)
|
cards_of_player.append(selected_card)
|
||||||
|
|
||||||
# create a list that contains every player, their deck and successes
|
# create a list that contains every player, their deck and successes
|
||||||
players_with_cards.append({"player": players[i], "cards_on_hand": cards_of_player, "quartet": 0})
|
players_with_cards.append(
|
||||||
|
{"player": players[i], "cards_on_hand": cards_of_player, "quartet": 0})
|
||||||
|
|
||||||
return card_stack, players_with_cards, players
|
return card_stack, players_with_cards, players
|
||||||
|
|
||||||
#def the_winner_is():
|
|
||||||
|
def the_winner_is():
|
||||||
"""
|
"""
|
||||||
counts the number of quartets
|
counts the number of quartets
|
||||||
a player has made, and chooses the
|
a player has made, and chooses the
|
||||||
winner, who made the most
|
winner, who made the most
|
||||||
"""
|
"""
|
||||||
#TODO
|
pass
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
|
||||||
# Call central_function() only if quartett.py is the main module
|
# Call central_function() only if quartett.py is the main module
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
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'},
|
||||||
|
{'id': '0', 'number': '0', 'letter': 'a'},
|
||||||
|
{'id': '28', 'number': '3', 'letter': 'a'},
|
||||||
|
{'id': '26', 'number': '3', 'letter': 'a'},
|
||||||
|
{'id': '5', 'number': '0', 'letter': 'a'},
|
||||||
|
{'id': '9', 'number': '1', 'letter': 'b'},
|
||||||
|
{'id': '7', 'number': '0', 'letter': 'h'}],
|
||||||
|
'quartet': 0}
|
||||||
|
drop_cards_help(p)
|
||||||
|
# central_function()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
players_with_cards = [
|
players_with_cards = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user