some refactoring and rule improvements

This commit is contained in:
Jannes Höke
2016-03-01 01:25:26 +01:00
parent 0d381ddf4d
commit b0bdbe0d0f
4 changed files with 191 additions and 123 deletions

View File

@ -27,9 +27,12 @@ class Player(object):
self._prev = self
game.current_player = self
for i in range(6):
for i in range(7):
self.cards.append(self.game.deck.draw())
self.bluffing = False
self.drew = False
def leave(self):
self.next.prev = self.prev
self.prev.next = self.next
@ -76,29 +79,34 @@ class Player(object):
self.logger.debug("Last card was" + str(last))
for card in self.cards:
self.logger.debug("Checking card " + str(card))
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")
continue
if self.card_playable(card, playable):
self.logger.debug("Matching!")
playable.append(card)
if last.value == c.DRAW_TWO and not \
(card.value == c.DRAW_TWO or
card.special == c.DRAW_FOUR or
not self.game.draw_counter):
self.logger.debug("Player has to draw and can't counter")
continue
if last.special == c.DRAW_FOUR and self.game.draw_counter:
self.logger.debug("Player has to draw and can't counter")
continue
if not last.color or card in playable:
self.logger.debug("Last card has no color or the card was "
"already added to the list")
continue
self.logger.debug("Matching!")
playable.append(card)
self.bluffing = bool(len(playable) - 1)
return playable
def card_playable(self, card, playable):
is_playable = True
last = self.game.last_card
self.logger.debug("Checking card " + str(card))
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
if last.value == c.DRAW_TWO and not \
(card.value == c.DRAW_TWO or
card.special == c.DRAW_FOUR or
not self.game.draw_counter):
self.logger.debug("Player has to draw and can't counter")
is_playable = False
if last.special == c.DRAW_FOUR and self.game.draw_counter:
self.logger.debug("Player has to draw and can't counter")
is_playable = False
if not last.color or card in playable:
self.logger.debug("Last card has no color or the card was "
"already added to the list")
is_playable = False
return is_playable