some refactoring and rule improvements
This commit is contained in:
56
player.py
56
player.py
@ -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
|
||||
|
Reference in New Issue
Block a user