From 8c09399ef7bb431898d9b12797197bc7d013642b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 6 May 2019 14:57:04 +0300 Subject: [PATCH] Prevent playing the same card twice with multiblanks --- gameloop.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gameloop.py b/gameloop.py index 078477c..ecf34cf 100644 --- a/gameloop.py +++ b/gameloop.py @@ -4,6 +4,11 @@ from collections import namedtuple import cardcast_api +# TODO: rando +# TODO: $0 support +# TODO: collapse several _ in a row into one +# TODO: keep track of where cards come from purge from hand when deck remove + class events(enum.Enum): quit, nick_change, status, start, ready, unready, kill, join, leave, players, deck_add, deck_add_random, deck_remove, deck_list, limit, card, cards = range(17) @@ -569,10 +574,21 @@ def game(send, notice, get_event): notice(nick, 'You\'ll get to choose next round') continue + # 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)) + continue + selected_cards = [] for choice in choices: if 0 <= choice < len(player.hand): - selected_cards.append(choice) + if choice not in selected_cards: + selected_cards.append(choice) + else: + notice(nick, 'Can\'t play the same card twice') + break else: notice(nick, '%i not in your hand' % choice) break @@ -581,13 +597,6 @@ def game(send, notice, get_event): # Failed to use some choice continue - # 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(selected_cards) != len(round_call_card) - 1: - notice(nick, 'Select %i card(s)' % (len(round_call_card) - 1)) - continue - card_choices[player] = selected_cards if player in choosers: choosers.remove(player)