forked from test/mau_mau_bot
Update player.py
Adding a new mode part in the function _card_playable.
This commit is contained in:
parent
393da434e8
commit
4c386218b0
1 changed files with 43 additions and 18 deletions
29
player.py
29
player.py
|
@ -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,8 +160,10 @@ 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 mode == 0: # This mode is to apply the original rule
|
||||||
if (card.color != last.color and card.value != last.value and
|
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")
|
||||||
|
@ -180,7 +182,30 @@ class Player(object):
|
||||||
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):
|
||||||
|
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):
|
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
|
||||||
|
|
Loading…
Reference in a new issue