From 4c386218b04a32e37390d33710fd3aff6dfc1778 Mon Sep 17 00:00:00 2001 From: Karho Date: Fri, 24 Feb 2017 14:15:08 +0800 Subject: [PATCH] Update player.py Adding a new mode part in the function _card_playable. --- player.py | 61 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/player.py b/player.py index c39befa..656c21f 100644 --- a/player.py +++ b/player.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # Telegram bot to play UNO in group chats -# Copyright (c) 2016 Jannes Höke +# Copyright (c) 2016 - 2017 Jannes Höke and Karho Yau # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -160,29 +160,54 @@ class Player(object): is_playable = True last = self.game.last_card + mode = self.game.mode self.logger.debug("Checking card " + str(card)) - if (card.color != last.color and card.value != last.value and + if mode == 0: # This mode is to apply the original rule + if (card.color != last.color and card.value != last.value and not card.special): - self.logger.debug("Card's color or value doesn't match") - is_playable = False - elif last.value == c.DRAW_TWO and self.game.draw_counter: """and not \ + self.logger.debug("Card's color or value doesn't match") + is_playable = False + elif last.value == c.DRAW_TWO and self.game.draw_counter: """and not \ (card.value == c.DRAW_TWO or card.special == c.DRAW_FOUR):""" - self.logger.debug("Player has to draw and can't counter") - is_playable = False - elif last.special == c.DRAW_FOUR and self.game.draw_counter: """and not card.special == c.DRAW_FOUR:""" - self.logger.debug("Player has to draw and can't counter") - is_playable = False - elif (last.special == c.CHOOSE or last.special == c.DRAW_FOUR) and \ + self.logger.debug("Player has to draw and can't counter") + is_playable = False + elif last.special == c.DRAW_FOUR and self.game.draw_counter: """and not card.special == c.DRAW_FOUR:""" + self.logger.debug("Player has to draw and can't counter") + is_playable = False + elif (last.special == c.CHOOSE or last.special == c.DRAW_FOUR) and \ (card.special == c.CHOOSE or card.special == c.DRAW_FOUR): """(last.special == c.CHOOSE and (card.special == c.CHOOSE or card.special == c.DRAW_FOUR)) or \ (last.special == c.DRAW_FOUR and card.special == c.CHOOSE):""" - self.logger.debug("Can't play colorchooser on another one") - is_playable = False - # Prevent game being locked by choosing colors. - # When player is going to leave and he didn't select a color, it cause game locks. - elif not last.color and (last.special != c.CHOOSE and last.special != c.DRAW_FOUR): - self.logger.debug("Last card has no color") - is_playable = False + self.logger.debug("Can't play colorchooser on another one") + is_playable = False + # Prevent game being locked by choosing colors. + # When player is going to leave and he doesn't select a color, it causes game lock. + elif not last.color and (last.special != c.CHOOSE and last.special != c.DRAW_FOUR): + self.logger.debug("Last card has no color") + is_playable = False + + elif mode == 1: # This mode is to apply the Progressive UNO rule. + if (card.color != last.color and card.value != last.value and + not card.special): + self.logger.debug("Card's color or value doesn't match") + is_playable = False + elif last.value == c.DRAW_TWO and self.game.draw_counter and not \ + card.value == c.DRAW_TWO: + self.logger.debug("Player has to draw and can't counter") + is_playable = False + elif last.special == c.DRAW_FOUR and self.game.draw_counter and not \ + card.special == c.DRAW_FOUR: + self.logger.debug("Player has to draw and can't counter") + is_playable = False + elif (last.special == c.CHOOSE and (card.special == c.CHOOSE or card.special == c.DRAW_FOUR)) or \ + (last.special == c.DRAW_FOUR and card.special == c.CHOOSE): + self.logger.debug("Can't play colorchooser on another one") + is_playable = False + # Prevent game being locked by choosing colors. + # When player is going to leave and he doesn't select a color, it causes game lock. + elif not last.color and (last.special != c.CHOOSE and last.special != c.DRAW_FOUR): + self.logger.debug("Last card has no color") + is_playable = False return is_playable