Update player.py

Adding a new mode part in the function _card_playable.
This commit is contained in:
Karho 2017-02-24 14:15:08 +08:00 committed by GitHub
parent 393da434e8
commit 4c386218b0

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Telegram bot to play UNO in group chats # Telegram bot to play UNO in group chats
# Copyright (c) 2016 Jannes Höke <uno@jhoeke.de> # Copyright (c) 2016 - 2017 Jannes Höke <uno@jhoeke.de> and Karho Yau
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -160,29 +160,54 @@ class Player(object):
is_playable = True is_playable = True
last = self.game.last_card last = self.game.last_card
mode = self.game.mode
self.logger.debug("Checking card " + str(card)) 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): not card.special):
self.logger.debug("Card's color or value doesn't match") self.logger.debug("Card's color or value doesn't match")
is_playable = False is_playable = False
elif last.value == c.DRAW_TWO and self.game.draw_counter: """and not \ elif last.value == c.DRAW_TWO and self.game.draw_counter: """and not \
(card.value == c.DRAW_TWO or card.special == c.DRAW_FOUR):""" (card.value == c.DRAW_TWO or card.special == c.DRAW_FOUR):"""
self.logger.debug("Player has to draw and can't counter") self.logger.debug("Player has to draw and can't counter")
is_playable = False is_playable = False
elif last.special == c.DRAW_FOUR and self.game.draw_counter: """and not card.special == c.DRAW_FOUR:""" 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") self.logger.debug("Player has to draw and can't counter")
is_playable = False is_playable = False
elif (last.special == c.CHOOSE or last.special == c.DRAW_FOUR) and \ elif (last.special == c.CHOOSE or last.special == c.DRAW_FOUR) and \
(card.special == c.CHOOSE or card.special == c.DRAW_FOUR): (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.CHOOSE and (card.special == c.CHOOSE or card.special == c.DRAW_FOUR)) or \
(last.special == c.DRAW_FOUR and card.special == c.CHOOSE):""" (last.special == c.DRAW_FOUR and card.special == c.CHOOSE):"""
self.logger.debug("Can't play colorchooser on another one") self.logger.debug("Can't play colorchooser on another one")
is_playable = False is_playable = False
# Prevent game being locked by choosing colors. # Prevent game being locked by choosing colors.
# When player is going to leave and he didn't select a color, it cause game locks. # 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): elif not last.color and (last.special != c.CHOOSE and last.special != c.DRAW_FOUR):
self.logger.debug("Last card has no color") self.logger.debug("Last card has no color")
is_playable = False 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 return is_playable