Пример #1
0
    def __isstraightflush(self):
        #log.logger.debug('Hand.__isstraightflush()')

        hist = []
        result = 0

        for card in self.cards:
            if card.suit() == self.flushcard.suit():
                hist.append(card)

        hist.sort()
        hist.reverse()

        newhr = rlast = hist[0].rank()
        i = seq = 1
        while i < len(hist):
            if hist[i].rank() == rlast - 1:
                seq += 1
                rlast = hist[i].rank()
                i += 1
            else:
                seq = 1
                newhr = rlast = hist[i].rank()
                i += 1

            if seq == 5:
                break

        if seq == 5:
            self.straighthi = newhr
            result = 1

        elif seq == 4 and newhr == 3 and hist[0].rank() == 12:
            self.straighthi = newhr
            result = 1

        return result
Пример #2
0
    def __isstraightflush(self):
        #log.logger.debug('Hand.__isstraightflush()')
        
        hist = []
        result = 0

        for card in self.cards:
            if card.suit() == self.flushcard.suit():
                hist.append(card)

        hist.sort()
        hist.reverse()

        newhr = rlast = hist[0].rank()
        i = seq = 1
        while i < len(hist):
            if hist[i].rank() == rlast - 1:
                seq += 1
                rlast = hist[i].rank()
                i += 1
            else:
                seq = 1
                newhr = rlast = hist[i].rank()
                i += 1            

            if seq == 5:
                break

        if seq == 5:
            self.straighthi = newhr
            result = 1

        elif seq == 4 and newhr == 3 and hist[0].rank() == 12:
            self.straighthi = newhr
            result = 1

        return result
Пример #3
0
    def evaluate(self):
        #log.logger.debug('Hand.evaluate()')

        rhist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        shist = [0, 0, 0, 0]
        flushtop = [0, 0, 0, 0]
        hicard = 0
        bucketsum = 0
        hf = nhf = 0
        hfr = nhfr = 0

        # Fill rank histogram
        for card in self.cards:
            arank = card.rank()

            rhist[arank] += 1
            if arank > hicard:
                hicard = arank

            asuit = card.suit()
            shist[asuit] += 1

        # Sum buckets using cards as indices
        for card in self.cards:
            arank = card.rank()
            bucketsum += rhist[arank]
            freq = rhist[arank]
            asuit = card.suit()

            if shist[asuit] >= 5:
                self.type = Hand.TYPE_FL
                self.flushcard = card

                if arank > flushtop[asuit]:
                    flushtop[asuit] = arank

            if freq > hf:
                nhf = hf
                hf = freq
                nhfr = hfr
                hfr = arank
            elif freq == hf:
                if arank > hfr:
                    nhf = hf
                    hf = freq
                    nhfr = hfr
                    hfr = arank
                elif arank < hfr:
                    if freq > nhf or arank >= nhfr:
                        nhf = freq
                        nhfr = arank
            elif freq > nhf:
                nhf = freq
                nhfr = arank
            elif freq == nhf and arank >= nhfr:
                nhfr = arank

        self.hi = hfr
        self.lo = nhfr

        # 4 2 1 or 4 3
        if bucketsum == 21 or bucketsum == 25:
            self.type = Hand.TYPE_4K

        # 3 2 1 1 or 3 2 2
        elif bucketsum == 15 or bucketsum == 17:
            self.type = Hand.TYPE_FH

        # 3 3 1 or 4 1 1 1
        elif bucketsum == 19:
            if hf == 4:
                self.type = Hand.TYPE_4K
            else:
                self.type = Hand.TYPE_FH

        # 2 2 2 1 or 3 1 1 1 1
        elif bucketsum == 13:
            if hf == 2:
                self.type = Hand.TYPE_2P
            else:
                self.straighthi = hicard
                if self.type == Hand.TYPE_FL:
                    if self.__isstraightflush():
                        self.type = Hand.TYPE_SF
                        #DEBUG
                        #print 'straighthi: %d' %self.straighthi
                        #DEBUG
                        self.hi = self.straighthi
                    else:
                        self.hi = flushtop[self.flushcard.suit()]
                elif self.__isstraight(rhist):
                    self.type = Hand.TYPE_ST
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.type = Hand.TYPE_3K

        # 2 2 1 1 1
        elif bucketsum == 11:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_2P

        # 2 1 1 1 1 1
        elif bucketsum == 9:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_1P

        # 1 1 1 1 1 1 1
        elif bucketsum == 7:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_NP
                self.hi = hicard

        return self.type
Пример #4
0
    def evaluate(self):
        #log.logger.debug('Hand.evaluate()')

        rhist = [0,0,0,0,0,0,0,0,0,0,0,0,0]
        shist = [0,0,0,0]
        flushtop = [0,0,0,0]
        hicard = 0
        bucketsum = 0
        hf = nhf = 0
        hfr = nhfr = 0

        # Fill rank histogram
        for card in self.cards:
            arank = card.rank()

            rhist[arank] += 1
            if arank > hicard:
                hicard = arank

            asuit = card.suit()
            shist[asuit] += 1

        # Sum buckets using cards as indices
        for card in self.cards:
            arank = card.rank()
            bucketsum += rhist[arank]
            freq = rhist[arank]
            asuit = card.suit()

            if shist[asuit] >= 5:
                self.type = Hand.TYPE_FL
                self.flushcard = card

                if arank > flushtop[asuit]:
                    flushtop[asuit] = arank

            if freq > hf:
                nhf = hf
                hf  = freq
                nhfr = hfr
                hfr = arank
            elif freq == hf:
                if arank > hfr:
                    nhf = hf
                    hf  = freq
                    nhfr = hfr
                    hfr = arank
                elif arank < hfr:
                    if freq > nhf or arank >= nhfr:
                        nhf = freq
                        nhfr = arank
            elif freq > nhf:
                nhf = freq
                nhfr = arank
            elif freq == nhf and arank >= nhfr:
                nhfr = arank

        self.hi = hfr
        self.lo = nhfr

        # 4 2 1 or 4 3
        if bucketsum == 21 or bucketsum == 25:
            self.type = Hand.TYPE_4K

        # 3 2 1 1 or 3 2 2
        elif bucketsum == 15 or bucketsum == 17:
            self.type = Hand.TYPE_FH

        # 3 3 1 or 4 1 1 1
        elif bucketsum == 19:
            if hf == 4:
                self.type = Hand.TYPE_4K
            else:
                self.type = Hand.TYPE_FH

        # 2 2 2 1 or 3 1 1 1 1
        elif bucketsum == 13:
            if hf == 2:
                self.type = Hand.TYPE_2P
            else:
                self.straighthi = hicard
                if self.type == Hand.TYPE_FL:
                    if self.__isstraightflush():
                        self.type = Hand.TYPE_SF
                        #DEBUG
                        #print 'straighthi: %d' %self.straighthi
                        #DEBUG
                        self.hi = self.straighthi
                    else:
                        self.hi = flushtop[self.flushcard.suit()]
                elif self.__isstraight(rhist):
                    self.type = Hand.TYPE_ST
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.type = Hand.TYPE_3K
                        
        # 2 2 1 1 1
        elif bucketsum == 11:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_2P

        # 2 1 1 1 1 1
        elif bucketsum == 9:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_1P

        # 1 1 1 1 1 1 1
        elif bucketsum == 7:
            self.straighthi = hicard
            if self.type == Hand.TYPE_FL:
                if self.__isstraightflush():
                    self.type = Hand.TYPE_SF
                    #DEBUG
                    #print 'straighthi: %d' %self.straighthi
                    #DEBUG
                    self.hi = self.straighthi
                else:
                    self.hi = flushtop[self.flushcard.suit()]
            elif self.__isstraight(rhist):
                self.type = Hand.TYPE_ST
                #DEBUG
                #print 'straighthi: %d' %self.straighthi
                #DEBUG
                self.hi = self.straighthi
            else:
                self.type = Hand.TYPE_NP
                self.hi = hicard

        return self.type
Пример #5
0
def is_flush(cards):
    return len(set([card.suit(c) for c in cards])) == 1