Keep track of where cards come from
This commit is contained in:
parent
3328545bf1
commit
7d905b3b95
20
gameloop.py
20
gameloop.py
|
@ -17,6 +17,8 @@ Deck = namedtuple('Deck', ['code', 'name', 'author', 'call_count', 'response_cou
|
||||||
|
|
||||||
Limit = namedtuple('Limit', ['type', 'number'])
|
Limit = namedtuple('Limit', ['type', 'number'])
|
||||||
|
|
||||||
|
Card = namedtuple('Card', ['deck', 'text'])
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, nick):
|
def __init__(self, nick):
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
|
@ -392,7 +394,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
|
|
||||||
# See comment about mutation in deal_responses()
|
# See comment about mutation in deal_responses()
|
||||||
index = random.randrange(len(deck.calls))
|
index = random.randrange(len(deck.calls))
|
||||||
return deck.calls.pop(index)
|
return Card(deck, deck.calls.pop(index))
|
||||||
|
|
||||||
def deal_responses(need_responses):
|
def deal_responses(need_responses):
|
||||||
nonlocal decks
|
nonlocal decks
|
||||||
|
@ -407,7 +409,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
# We generate an index and pop that, since that makes
|
# We generate an index and pop that, since that makes
|
||||||
# it easier to mutate the list in place
|
# it easier to mutate the list in place
|
||||||
index = random.randrange(len(deck.responses))
|
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
|
# Shuffle the responses at the end, as otherwise the first
|
||||||
# cards are more likely to have come from small decks than
|
# 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):
|
def send_cards(nick):
|
||||||
nonlocal players
|
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)
|
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]
|
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('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:
|
for nick in players:
|
||||||
if players[nick] is not czar:
|
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
|
# Round call card has N parts. Between each of
|
||||||
# those parts goes one response card. Therefore
|
# those parts goes one response card. Therefore
|
||||||
# there should be N - 1 response cards
|
# there should be N - 1 response cards
|
||||||
if len(choices) != len(round_call_card) - 1:
|
if len(choices) != len(round_call_card.text) - 1:
|
||||||
notice(nick, 'Select %i card(s)' % (len(round_call_card) - 1))
|
notice(nick, 'Select %i card(s)' % (len(round_call_card.text) - 1))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
selected_cards = []
|
selected_cards = []
|
||||||
|
@ -594,7 +596,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
card_choices[player] = selected_cards
|
card_choices[player] = selected_cards
|
||||||
if player in choosers:
|
if player in choosers:
|
||||||
choosers.remove(player)
|
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:
|
elif event == events.cards:
|
||||||
nick, = args
|
nick, = args
|
||||||
|
@ -624,7 +626,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
# Display the cards
|
# Display the cards
|
||||||
choosers = random.sample(card_choices.keys(), k = len(card_choices))
|
choosers = random.sample(card_choices.keys(), k = len(card_choices))
|
||||||
for index, player in enumerate(choosers):
|
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:
|
while True:
|
||||||
if len(players) < 2:
|
if len(players) < 2:
|
||||||
|
@ -666,7 +668,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
# Winner is Czar semantics
|
# Winner is Czar semantics
|
||||||
czar = player
|
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
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue