예제 #1
0
    def preferred_trump(self):
        """
            current implementation notes:
                - need to determine some sort of algorithm to determine preferred trump for a hand
                    - weigh value of cards vs. number of cards
                        - something like compare sum of suit enum.values
                    - account for left and right bower in the calculation

        :return: trump: Suit
        """
        suits = dict({})
        for card in self.cards:
            suit = card.suit.value
            is_bower = Card.is_bower(card, suit)
            value = card.value.value
            if is_bower:
                value = is_bower
                try:
                    suits[Suit.opposite_suit(suit)] += Value.l_bower.value
                except KeyError:
                    suits[Suit.opposite_suit(suit)] = Value.l_bower.value
            try:
                suits[suit] += value
            except KeyError:
                suits[suit] = value
        max_k = max_v = 0
        for (k, v) in suits.items():
            if v > max_v:
                max_k = k
                max_v = v
        return max_k
예제 #2
0
 def suit_strength(self, suit):
     for card in self.cards:
         suit = card.suit.value
         is_bower = Card.is_bower(card, suit)
         value = card.value.value
         if is_bower:
             value = is_bower
             try:
                 suits[Suit.opposite_suit(suit)] += Value.l_bower.value
             except KeyError:
                 suits[Suit.opposite_suit(suit)] = Value.l_bower.value
         try:
             suits[suit] += value
         except KeyError:
             suits[suit] = value
예제 #3
0
 def is_bower(card, trump):
     """
         checks if the given card is a bower of the suit and returns the internal value (Value.r_bower or Value.l_bower)
         if it is, else returns False
     :param card: Card
     :param trump: Suit.VALUE or str
     :return: Value.r_bower or Value.l_bower if is bower, else returns False
     """
     if isinstance(trump, Suit):
         trump = trump.value
     if card.value.name == 'jack':
         if card.suit.value == trump:
             return Value.r_bower.value
         elif not Suit.is_red(trump) ^ Suit.is_red(card.suit):
             return Value.l_bower.value
         else:
             return False
예제 #4
0
    def from_str(self, s):
        card_s = [i.strip().upper() for i in s.split(",")]
        fin = []
        for card in card_s:
            val = Value.get(card[:-1])
            suit = Suit.get(card[-1:])

            fin.append(Card(val, suit))

        return (fin, )
예제 #5
0
 def assign_bowers(self, trump):
     if self.value.name == 'jack':
         if self.is_trump:
             self.value = Value.r_bower
         if not Suit.is_red(trump) ^ Suit.is_red(self.suit):
             self.value = Value.l_bower
예제 #6
0
 def assign_trump(self, trump):
     self.is_trump = self.suit == Suit.get(trump)
     self.assign_bowers(Suit.get(trump))
예제 #7
0
 def from_str(self, s):
     return (Value.get(s[:-1]), Suit.get(s[-1:]))