From 1d10388d8eb3c086c792f3b71bd6e8bceaf30d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Sun, 8 May 2016 17:03:29 +0200 Subject: [PATCH] reduce waiting time for repeated skipping and remove after four successive skips --- bot.py | 44 +++++++++++++++++++++++++++++++++++++------- player.py | 1 + 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index aa6fd91..dc2fcd1 100644 --- a/bot.py +++ b/bot.py @@ -356,13 +356,39 @@ def skip_player(bot, update): update.message.message_id) return - game.current_player.anti_cheat += 1 - game.current_player.cards.append(game.deck.draw()) - game.turn() - send_async(bot, chat_id, - text="Next player: %s" - % display_name(game.current_player.user)) - return + elif game.current_player.waiting_time > 0: + game.current_player.anti_cheat += 1 + game.current_player.waiting_time -= 30 + game.current_player.cards.append(game.deck.draw()) + game.turn() + send_async(bot, chat_id, + text="Waiting time to skip this player has " + "been reduced to %d seconds.\n" + "Next player: %s" + % (game.current_player.waiting_time, + display_name(game.current_player.user))) + return + + elif len(game.players) > 2: + send_async(bot, chat_id, + text="%s was skipped four times in a row " + "and has been removed from the game.\n" + "Next player: %s" + % (display_name(game.current_player.user), + display_name( + game.current_player.next.user))) + + gm.leave_game(game.current_player.user, chat_id) + return + else: + send_async(bot, chat_id, + text="%s was skipped four times in a row " + "and has been removed from the game.\n" + "The game ended." + % display_name(game.current_player.user)) + + gm.end_game(chat_id, game.current_player.user) + return def help(bot, update): @@ -482,6 +508,10 @@ def process_result(bot, update): def do_play_card(bot, chat_id, game, player, result_id, user): + if player.waiting_time < 90: + player.waiting_time = 90 + send_async(bot, chat_id, text="Waiting time for %s has been reset to " + "90 seconds" % display_name(user)) card = c.from_str(result_id) game.play_card(card) player.cards.remove(card) diff --git a/player.py b/player.py index fdaec08..a8531ff 100644 --- a/player.py +++ b/player.py @@ -55,6 +55,7 @@ class Player(object): self.drew = False self.anti_cheat = 0 self.turn_started = datetime.now() + self.waiting_time = 90 def leave(self): """ Leave the current game """