Keep track of where cards come from

This commit is contained in:
Juhani Krekelä 2019-05-06 18:56:26 +03:00
parent 3328545bf1
commit 7d905b3b95
1 changed files with 11 additions and 9 deletions

View File

@ -17,6 +17,8 @@ Deck = namedtuple('Deck', ['code', 'name', 'author', 'call_count', 'response_cou
Limit = namedtuple('Limit', ['type', 'number'])
Card = namedtuple('Card', ['deck', 'text'])
class Player:
def __init__(self, nick):
self.nick = nick
@ -392,7 +394,7 @@ def game(send, notice, voice, devoice, get_event):
# See comment about mutation in deal_responses()
index = random.randrange(len(deck.calls))
return deck.calls.pop(index)
return Card(deck, deck.calls.pop(index))
def deal_responses(need_responses):
nonlocal decks
@ -407,7 +409,7 @@ def game(send, notice, voice, devoice, get_event):
# We generate an index and pop that, since that makes
# it easier to mutate the list in place
index = random.randrange(len(deck.responses))
responses.append(deck.responses.pop(index))
responses.append(Card(deck, deck.responses.pop(index)))
# Shuffle the responses at the end, as otherwise the first
# cards are more likely to have come from small decks than
@ -475,7 +477,7 @@ def game(send, notice, voice, devoice, get_event):
def send_cards(nick):
nonlocal players
cards = ' | '.join('%i: [%s]' % (index, sanitize(card)) for index, card in enumerate(players[nick].hand))
cards = ' | '.join('%i: [%s]' % (index, sanitize(card.text)) for index, card in enumerate(players[nick].hand))
notice(nick, cards)
@ -528,7 +530,7 @@ def game(send, notice, voice, devoice, get_event):
choosers = [i for i in players.values() if i is not czar]
send('Round %i. %s choose your cards' % (round_number, ', '.join(i.nick for i in choosers)))
send('[%s]' % '_'.join(sanitize(part) for part in round_call_card))
send('[%s]' % '_'.join(sanitize(part) for part in round_call_card.text))
for nick in players:
if players[nick] is not czar:
@ -571,8 +573,8 @@ def game(send, notice, voice, devoice, get_event):
# Round call card has N parts. Between each of
# those parts goes one response card. Therefore
# there should be N - 1 response cards
if len(choices) != len(round_call_card) - 1:
notice(nick, 'Select %i card(s)' % (len(round_call_card) - 1))
if len(choices) != len(round_call_card.text) - 1:
notice(nick, 'Select %i card(s)' % (len(round_call_card.text) - 1))
continue
selected_cards = []
@ -594,7 +596,7 @@ def game(send, notice, voice, devoice, get_event):
card_choices[player] = selected_cards
if player in choosers:
choosers.remove(player)
notice(nick, combine_cards(round_call_card, [player.hand[i] for i in selected_cards]))
notice(nick, combine_cards(round_call_card.text, [player.hand[i].text for i in selected_cards]))
elif event == events.cards:
nick, = args
@ -624,7 +626,7 @@ def game(send, notice, voice, devoice, get_event):
# Display the cards
choosers = random.sample(card_choices.keys(), k = len(card_choices))
for index, player in enumerate(choosers):
send('%i: %s' % (index, combine_cards(round_call_card, [player.hand[i] for i in card_choices[player]])))
send('%i: %s' % (index, combine_cards(round_call_card.text, [player.hand[i].text for i in card_choices[player]])))
while True:
if len(players) < 2:
@ -666,7 +668,7 @@ def game(send, notice, voice, devoice, get_event):
# Winner is Czar semantics
czar = player
send('The winner is %s with: %s' % (player.nick, combine_cards(round_call_card, [player.hand[i] for i in card_choices[player]])))
send('The winner is %s with: %s' % (player.nick, combine_cards(round_call_card.text, [player.hand[i].text for i in card_choices[player]])))
break