AI card selection is now complete, edited print statements in pretty_print_deck() and steal(), all_quartets is now working
This commit is contained in:
parent
1f80056d2e
commit
7b6851c9de
54
quartett.py
54
quartett.py
|
@ -36,7 +36,6 @@ def central_function():
|
|||
|
||||
for i in range(len(players)): # check if any card deck is empty
|
||||
switch = bool(players_with_cards[i]['cards_on_hand'])
|
||||
print(switch)
|
||||
|
||||
active += 1
|
||||
if active >= len(players):
|
||||
|
@ -55,28 +54,29 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
|
|||
switch = True
|
||||
|
||||
while switch:
|
||||
print(active)
|
||||
# print(active)
|
||||
players_without_active = copy.copy(players)
|
||||
players_without_active.pop(active)
|
||||
|
||||
if players[active] == "player0": # human player
|
||||
pretty_print_deck(players_with_cards, active)
|
||||
print('Folgende Spieler stehen zur Verfügung:')
|
||||
print(players_without_active)
|
||||
# chosen_player enthält den index in der players liste
|
||||
chosen_player = players.index(clean_input.io_str(
|
||||
'Welchen Spieler möchtest du befragen? ', players_without_active))
|
||||
print("chosen player", chosen_player)
|
||||
# print("chosen player", chosen_player)
|
||||
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']:
|
||||
steal(active, chosen_player, players_with_cards, player_request)
|
||||
drop_cards(players_with_cards, active)
|
||||
drop_cards(players_with_cards, all_quartets, active)
|
||||
|
||||
else:
|
||||
print("Diese Karte hat der Spieler nicht. Der nächste Spieler ist dran...")
|
||||
# end of round
|
||||
# except if stack is not empty, which is not only the case with two players
|
||||
if card_stack == True:
|
||||
if card_stack:
|
||||
# last card from the stack gets added to active player's hand
|
||||
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
|
||||
|
||||
|
@ -97,9 +97,27 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack,
|
|||
# select card
|
||||
player_request = random.choice(cards_to_choose_from)
|
||||
|
||||
print("AI deck:", players_with_cards[active])
|
||||
print("AI choose:", chosen_player)
|
||||
print("AI card wish", player_request)
|
||||
print(
|
||||
f"{players[active]} fragt {players[chosen_player]} nach der Karte {player_request}.")
|
||||
|
||||
if player_request in players_with_cards[chosen_player]['cards_on_hand']:
|
||||
steal(active, chosen_player, players_with_cards, player_request)
|
||||
drop_cards(players_with_cards, all_quartets, active)
|
||||
|
||||
else:
|
||||
print(
|
||||
f"{players[chosen_player]} hat die Karte {player_request} nicht. Der nächste Spieler ist dran...")
|
||||
# end of round
|
||||
# except if stack is not empty, which is not only the case with two players
|
||||
if card_stack:
|
||||
# last card from the stack gets added to active player's hand
|
||||
players_with_cards[active]['cards_on_hand'].append(card_stack.pop())
|
||||
|
||||
switch = False
|
||||
|
||||
# print("AI deck:", players_with_cards[active])
|
||||
# print("AI choose:", chosen_player)
|
||||
# print("AI card wish", player_request)
|
||||
|
||||
|
||||
def pretty_print_deck(players_with_cards, player):
|
||||
|
@ -110,6 +128,8 @@ def pretty_print_deck(players_with_cards, player):
|
|||
pretty_deck = []
|
||||
for card in players_with_cards[player]['cards_on_hand']:
|
||||
pretty_deck.append(card['number'] + card['letter'])
|
||||
|
||||
if player == 0:
|
||||
print("Dein Deck: ", pretty_deck)
|
||||
|
||||
|
||||
|
@ -118,12 +138,16 @@ def steal(active, chosen_player, players_with_cards, player_request):
|
|||
defines how the active players steals cards from chosen player
|
||||
:return: None
|
||||
"""
|
||||
print("player", chosen_player,
|
||||
"hat die Karte, die du haben möchtest und sie wandert in dein Deck.")
|
||||
if active == 0:
|
||||
print(f"player{chosen_player} hat die Karte, die du "
|
||||
"haben möchtest und sie wandert in dein Deck.")
|
||||
else:
|
||||
print(f"player{chosen_player} hat die Karte, die player{active}"
|
||||
"haben möchte nicht und sie wandert in sein Deck.")
|
||||
card_index = players_with_cards[chosen_player]['cards_on_hand'].index(player_request)
|
||||
players_with_cards[active]['cards_on_hand'].append(
|
||||
players_with_cards[chosen_player]['cards_on_hand'].pop(card_index))
|
||||
pretty_print_deck(players_with_cards, active)
|
||||
# pretty_print_deck(players_with_cards, active)
|
||||
|
||||
|
||||
def drop_cards(players_with_cards, all_quartets, active=None):
|
||||
|
@ -160,7 +184,13 @@ def drop_cards_help(p, all_quartets):
|
|||
p["quartet"] += 1
|
||||
print(f"{p['player']} legt das {quartet_letter}-Quartett ab...")
|
||||
|
||||
all_quartets.append(c for c in p["cards_on_hand"] if quartet_letter == c["letter"])
|
||||
# build list of cards that are now dropped
|
||||
q = [c for c in p["cards_on_hand"] if quartet_letter == c["letter"]]
|
||||
|
||||
# add quartet cards to list
|
||||
for c in q:
|
||||
all_quartets.append(c)
|
||||
|
||||
p["cards_on_hand"] = [c for c in p["cards_on_hand"] if quartet_letter != c["letter"]]
|
||||
|
||||
return p
|
||||
|
|
Loading…
Reference in New Issue