Ejemplo n.º 1
0
 def isTwoPairs(self):
     """ generated source for method isTwoPairs """
     highestTwoOfAKind = CardsUtil.getHighestOfSameRank(PokerHand.ONE_PAIR.getCardsRequired(), self.cards)
     if len(highestTwoOfAKind) == 0:
         raise Exception("No two of a kind found in Two pairs")
     nextHighestTwoOfAKind =CardsUtil.getHighestOfSameRankExcluding(PokerHand.ONE_PAIR.getCardsRequired(), self.cards, highestTwoOfAKind[0].getRank())
     if len(nextHighestTwoOfAKind) == 0:
         raise Exception("No second two of a kind found in Two pairs")
     twoPairs = highestTwoOfAKind + nextHighestTwoOfAKind
     twoPairs = twoPairs + CardsUtil.getHighestSortedAndExclude(5 - PokerHand.TWO_PAIRS.getCardsRequired(), self.cards, twoPairs)
     return Hand(twoPairs, PokerHand.TWO_PAIRS)
Ejemplo n.º 2
0
 def isFlush(self):
     """ generated source for method isFlush """
     potentialFlush = None
     for suit, cards in self.suitDistribution.iteritems():
         if len(cards) >= PokerHand.FLUSH.getCardsRequired():
             potentialFlush = cards
             break
     if potentialFlush == None:
         raise Exception("No Flush found")
     potentialFlush = CardsUtil.getHighestSortedAndExclude(PokerHand.FLUSH.getCardsRequired(), potentialFlush, None)
     return Hand(potentialFlush, PokerHand.FLUSH)
Ejemplo n.º 3
0
 def isOnePair(self):
     """ generated source for method isOnePair """
     potentialOnePair = None
     for rank, cards in self.rankDistribution.iteritems():
         if len(cards) == 2:
             if potentialOnePair != None:
                 raise Exception("Already found a pair, this hand contains two pairs")
             potentialOnePair = cards
         elif len(cards) > 2:
             raise Exception("There exists a better match than one pair")
     if potentialOnePair == None:
         raise Exception("No One pair found")
     restOfCards = CardsUtil.getHighestSortedAndExclude(5 - PokerHand.ONE_PAIR.getCardsRequired(), self.cards, potentialOnePair)
     potentialOnePair = sorted(potentialOnePair, key=lambda x: card_sort_value_by_suit(x))
     potentialOnePair = potentialOnePair + restOfCards
     return Hand(potentialOnePair, PokerHand.ONE_PAIR)
Ejemplo n.º 4
0
    def isFourOfAKind(self):
        """ generated source for method isFourOfAKind """
        #  Is there a rank that contains 4 cards?
        potentialFourOfAKind = None
        for rank, cards in self.rankDistribution.iteritems():
            if len(cards) == PokerHand.FOUR_OF_A_KIND.getCardsRequired():
                potentialFourOfAKind = cards
                break

        if potentialFourOfAKind == None:
            raise Exception("No Four of a kind found")

        #  Sort by suit
        potentialFourOfAKind = sorted(potentialFourOfAKind, key=lambda x: card_sort_value_by_suit(x), reverse=True)
        restOfCards = CardsUtil.getHighestSortedAndExclude(5 - PokerHand.FOUR_OF_A_KIND.getCardsRequired(), self.cards, potentialFourOfAKind)
        potentialFourOfAKind = potentialFourOfAKind + restOfCards

        return Hand(potentialFourOfAKind, PokerHand.FOUR_OF_A_KIND)
Ejemplo n.º 5
0
    def isThreeOfAKind(self):
        """ generated source for method isThreeOfAKind """
        #  Is there a rank that contains 3 cards?
        potentialThreeOfAKind = None
        for rank, threeOfAKind in self.rankDistribution.iteritems():
            if len(threeOfAKind) == PokerHand.THREE_OF_A_KIND.getCardsRequired():
                #  There might be more than one set of three-of-a-kind, choose
                #  the highest ranking one.
                if potentialThreeOfAKind != None:
                    if potentialThreeOfAKind[0].getRank().getOrderValue() < threeOfAKind[0].getRank().getOrderValue():
                        potentialThreeOfAKind = threeOfAKind
                else:
                    potentialThreeOfAKind = threeOfAKind

        if potentialThreeOfAKind is None:
            raise Exception("No Three of a kind found")

        potentialThreeOfAKind = sorted(potentialThreeOfAKind, key=lambda x: card_sort_value_by_suit(x), reverse=True)
        potentialThreeOfAKind = potentialThreeOfAKind + CardsUtil.getHighestSortedAndExclude(5 - PokerHand.THREE_OF_A_KIND.getCardsRequired(), self.cards, potentialThreeOfAKind)
        return Hand(potentialThreeOfAKind, PokerHand.THREE_OF_A_KIND)
Ejemplo n.º 6
0
    def isRoyalFlush(self):
        """ generated source for method isRoyalFlush """
        #  Is there a suit that contains 5 cards?
        potentialRoyalFlush = None
        for suit, cards in self.suitDistribution.iteritems():
            if len(cards) >= PokerHand.ROYAL_FLUSH.getCardsRequired():
                potentialRoyalFlush = cards
                break

        if potentialRoyalFlush == None:
            raise Exception("No Royal Flush found")

        potentialRoyalFlush = CardsUtil.getHighestSortedAndExclude(5, potentialRoyalFlush, None)
        counter = PokerHand.ROYAL_FLUSH.getCardsRequired() - 1

        checkList = [Rank.TEN, Rank.JACK, Rank.QUEEN, Rank.KING, Rank.ACE]
        for r in checkList:
            c = potentialRoyalFlush[counter];
            counter = counter - 1
            if r != c.getRank():
                raise Exception("No Royal Flush found")

        return Hand(potentialRoyalFlush, PokerHand.ROYAL_FLUSH)
Ejemplo n.º 7
0
 def isHighHand(self):
     """ generated source for method isHighHand """
     return Hand(CardsUtil.getHighestSortedAndExclude(5, self.cards, None), PokerHand.HIGH_HAND)