added list comrehension in AI branch of round(), AI can now choose a player and a card.
This commit is contained in:
parent
7937adc402
commit
8a8dfc92db
18
quartett.py
18
quartett.py
|
@ -31,7 +31,7 @@ def central_function():
|
||||||
# print("active", active) # debug
|
# print("active", active) # debug
|
||||||
drop_cards(players_with_cards, all_quartets)
|
drop_cards(players_with_cards, all_quartets)
|
||||||
while switch:
|
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
|
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'])
|
||||||
|
@ -44,7 +44,7 @@ def central_function():
|
||||||
# the_winner_is()
|
# 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
|
structures one round in the game
|
||||||
active player chooses another player from whom to steal a card
|
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
|
cards_to_choose_from = [c for c in complete_card_stack if
|
||||||
c not in players_with_cards[active]["cards_on_hand"]]
|
c not in players_with_cards[active]["cards_on_hand"]]
|
||||||
|
|
||||||
# TODO: check that all_quartets is consistent in the whole module
|
# 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
|
cards_to_choose_from = [c for c in cards_to_choose_from if
|
||||||
# c not in all_quartets]
|
c not in all_quartets]
|
||||||
|
|
||||||
|
# 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("AI choose:", chosen_player)
|
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):
|
||||||
|
@ -137,8 +141,6 @@ def drop_cards(players_with_cards, all_quartets, active=None):
|
||||||
p = players_with_cards[active]
|
p = players_with_cards[active]
|
||||||
drop_cards_help(p, all_quartets)
|
drop_cards_help(p, all_quartets)
|
||||||
|
|
||||||
return all_quartets
|
|
||||||
|
|
||||||
|
|
||||||
def drop_cards_help(p, 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"])
|
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"]]
|
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():
|
def initialize():
|
||||||
|
|
Loading…
Reference in New Issue