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