From 8a8dfc92dbe24361d3b7b6d3e44c415fd82969da Mon Sep 17 00:00:00 2001 From: Steinadler Date: Wed, 13 Jan 2021 16:53:07 +0100 Subject: [PATCH] added list comrehension in AI branch of round(), AI can now choose a player and a card. --- quartett.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/quartett.py b/quartett.py index dcec724..03a1a1d 100644 --- a/quartett.py +++ b/quartett.py @@ -31,7 +31,7 @@ def central_function(): # print("active", active) # debug drop_cards(players_with_cards, all_quartets) while switch: - round(card_stack, players_with_cards, players, active, complete_card_stack) + round(card_stack, players_with_cards, players, active, complete_card_stack, all_quartets) for i in range(len(players)): # check if any card deck is empty switch = bool(players_with_cards[i]['cards_on_hand']) @@ -44,7 +44,7 @@ def central_function(): # the_winner_is() -def round(card_stack, players_with_cards, players, active, complete_card_stack): +def round(card_stack, players_with_cards, players, active, complete_card_stack, all_quartets): ''' structures one round in the game active player chooses another player from whom to steal a card @@ -89,12 +89,16 @@ def round(card_stack, players_with_cards, players, active, complete_card_stack): cards_to_choose_from = [c for c in complete_card_stack if c not in players_with_cards[active]["cards_on_hand"]] - # TODO: check that all_quartets is consistent in the whole module - # cards_to_choose_from = [c for c in cards_to_choose_from if - # c not in all_quartets] + # get list of cards that are not on the hand of active AI player AND not in quartets + cards_to_choose_from = [c for c in cards_to_choose_from if + c not in all_quartets] + + # 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) def pretty_print_deck(players_with_cards, player): @@ -137,8 +141,6 @@ def drop_cards(players_with_cards, all_quartets, active=None): p = players_with_cards[active] drop_cards_help(p, all_quartets) - return all_quartets - def drop_cards_help(p, all_quartets): """ @@ -160,7 +162,7 @@ def drop_cards_help(p, all_quartets): all_quartets.append(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, all_quartets + return p def initialize():