Beispiel #1
0
def eval_post_flop_current(hole_cards, community_cards):
    board = []
    hand = []
    remaining_cards = all_cards[:]
    for card in hole_cards:
        new_card = Card.new(card[1] + card[0].lower())
        hand.append(new_card)
        remaining_cards.remove(new_card)
    for card in community_cards:
        new_card = Card.new(card[1] + card[0].lower())
        board.append(new_card)
        remaining_cards.remove(new_card)

    score = evaluator.evaluate(board, hand)

    rounds = 0
    wins = 0
    draws = 0
    for i in xrange(0, len(remaining_cards)):
        for j in xrange(i + 1, len(remaining_cards)):
            rounds += 1
            opp_hand = [remaining_cards[i], remaining_cards[j]]
            opp_score = evaluator.evaluate(board, opp_hand)
            if (opp_score > score):
                wins += 1
            # elif(evaluator.evaluate(board, opp_hand) < score):
            #     loses += 1
            elif (opp_score == score):
                draws += 1
    # print("Rounds played: " + str(rounds) + " Wins: " + str(wins) + " Draws: " + str(draws))
    return 100.0 * (float(wins) / rounds)
Beispiel #2
0
def eval_post_flop_rank(hole_cards, community_cards):
    board = []
    hand = []
    for card in hole_cards:
        hand.append(Card.new(card[1] + card[0].lower()))  # 9c, Ah, Kd etc..
    for card in community_cards:
        board.append(Card.new(card[1] + card[0].lower()))

    score = evaluator.evaluate(board, hand)
    return (
        7462 - score + 1
    ) / 7462.0 * 100  # there are only 7642 distinctly ranked hands in poker
Beispiel #3
0
    def straight_and_highcards(self, straights, highcards):
        """
        Unique five card sets. Straights and highcards.

        Reuses bit sequences from flush calculations.
        """
        rank = LookupTable.MAX_FLUSH + 1

        for s in straights:
            prime_product = Card.prime_product_from_rankbits(s)
            self.unsuited_lookup[prime_product] = rank
            rank += 1

        rank = LookupTable.MAX_PAIR + 1
        for h in highcards:
            prime_product = Card.prime_product_from_rankbits(h)
            self.unsuited_lookup[prime_product] = rank
            rank += 1
Beispiel #4
0
    def GetFullDeck():
        if Deck._FULL_DECK:
            return list(Deck._FULL_DECK)

        # create the standard 52 card deck
        for rank in Card.STR_RANKS:
            for suit, val in Card.CHAR_SUIT_TO_INT_SUIT.iteritems():
                Deck._FULL_DECK.append(Card.new(rank + suit))

        return list(Deck._FULL_DECK)
    def _five(self, cards):
        """
        Performs an evalution given cards in integer form, mapping them to
        a rank in the range [1, 7462], with lower ranks being more powerful.

        Variant of Cactus Kev's 5 card evaluator, though I saved a lot of memory
        space using a hash table and condensing some of the calculations.
        """
        # if flush
        if cards[0] & cards[1] & cards[2] & cards[3] & cards[4] & 0xF000:
            handOR = (cards[0] | cards[1] | cards[2] | cards[3]
                      | cards[4]) >> 16
            prime = Card.prime_product_from_rankbits(handOR)
            return self.table.flush_lookup[prime]

        # otherwise
        else:
            prime = Card.prime_product_from_hand(cards)
            return self.table.unsuited_lookup[prime]
Beispiel #6
0
 def __str__(self):
     return Card.print_pretty_cards(self.cards)
Beispiel #7
0
    def flushes(self):
        """
        Straight flushes and flushes.

        Lookup is done on 13 bit integer (2^13 > 7462):
        xxxbbbbb bbbbbbbb => integer hand index
        """

        # straight flushes in rank order
        straight_flushes = [
            7936,  # int('0b1111100000000', 2), # royal flush
            3968,  # int('0b111110000000', 2),
            1984,  # int('0b11111000000', 2),
            992,  # int('0b1111100000', 2),
            496,  # int('0b111110000', 2),
            248,  # int('0b11111000', 2),
            124,  # int('0b1111100', 2),
            62,  # int('0b111110', 2),
            31,  # int('0b11111', 2),
            4111  # int('0b1000000001111', 2) # 5 high
        ]

        # now we'll dynamically generate all the other
        # flushes (including straight flushes)
        flushes = []
        gen = self.get_lexographically_next_bit_sequence(int('0b11111', 2))

        # 1277 = number of high cards
        # 1277 + len(str_flushes) is number of hands with all cards unique rank
        for i in xrange(1277 + len(straight_flushes) -
                        1):  # we also iterate over SFs
            # pull the next flush pattern from our generator
            f = next(gen)

            # if this flush matches perfectly any
            # straight flush, do not add it
            notSF = True
            for sf in straight_flushes:
                # if f XOR sf == 0, then bit pattern
                # is same, and we should not add
                if not f ^ sf:
                    notSF = False

            if notSF:
                flushes.append(f)

        # we started from the lowest straight pattern, now we want to start ranking from
        # the most powerful hands, so we reverse
        flushes.reverse()

        # now add to the lookup map:
        # start with straight flushes and the rank of 1
        # since theyit is the best hand in poker
        # rank 1 = Royal Flush!
        rank = 1
        for sf in straight_flushes:
            prime_product = Card.prime_product_from_rankbits(sf)
            self.flush_lookup[prime_product] = rank
            rank += 1

        # we start the counting for flushes on max full house, which
        # is the worst rank that a full house can have (2,2,2,3,3)
        rank = LookupTable.MAX_FULL_HOUSE + 1
        for f in flushes:
            prime_product = Card.prime_product_from_rankbits(f)
            self.flush_lookup[prime_product] = rank
            rank += 1

        # we can reuse these bit sequences for straights
        # and high cards since they are inherently related
        # and differ only by context
        self.straight_and_highcards(straight_flushes, flushes)
Beispiel #8
0
def eval_post_flop_true(hole_cards, community_cards):
    board = []
    hand = []
    remaining_cards = all_cards[:]
    for card in hole_cards:
        new_card = Card.new(card[1] + card[0].lower())
        hand.append(new_card)
        remaining_cards.remove(new_card)
    for card in community_cards:
        new_card = Card.new(card[1] + card[0].lower())
        board.append(new_card)
        remaining_cards.remove(new_card)

    rounds = 0
    wins = 0
    draws = 0

    if (len(community_cards) == 5):  # (45 choose 2) = 990 iterations
        score = evaluator.evaluate(board, hand)
        for i in xrange(0, len(remaining_cards)):
            for j in xrange(i + 1, len(remaining_cards)):
                rounds += 1
                opp_hand = [remaining_cards[i], remaining_cards[j]]
                opp_score = evaluator.evaluate(board, opp_hand)
                if (opp_score > score):
                    wins += 1
                # elif(evaluator.evaluate(board, opp_hand) < score):
                #     loses += 1
                elif (opp_score == score):
                    draws += 1
        print("Rounds played: " + str(rounds) + " Wins: " + str(wins) +
              " Draws: " + str(draws))
        return (float(wins) / rounds) * 100.0
    elif (len(community_cards) == 4
          ):  # (46 choose 3) * (3 choose 1) = 45540 iterations
        for i in range(0, len(remaining_cards)):
            temp_board = board + [remaining_cards[i]]
            for j in xrange(0, len(remaining_cards)):
                if (i == j):
                    continue
                else:
                    for k in xrange(j + 1, len(remaining_cards)):
                        if ((i == k) or (j == k)):
                            continue
                        else:
                            rounds += 1
                            opp_hand = [remaining_cards[j], remaining_cards[k]]
                            opp_score = evaluator.evaluate(
                                temp_board, opp_hand)
                            score = evaluator.evaluate(temp_board, hand)
                            if (opp_score > score):
                                wins += 1
                            # elif(evaluator.evaluate(board, opp_hand) < score):
                            #     loses += 1
                            elif (opp_score < score):
                                draws += 1
        print("Rounds played: " + str(rounds) + " Wins: " + str(wins) +
              " Draws: " + str(draws))
        return (float(wins) / rounds) * 100.0
    elif (len(community_cards) == 3
          ):  # (47 choose 4) * (4 choose 2) = 1070190 iterations
        for h in xrange(0, len(remaining_cards)):
            temp_board = board + [remaining_cards[h]]
            for i in xrange(h + 1, len(remaining_cards)):
                temp_board_2 = temp_board + [remaining_cards[i]]
                for j in xrange(0, len(remaining_cards)):
                    if ((i == j) or (h == j)):
                        continue
                    else:
                        for k in xrange(j + 1, len(remaining_cards)):
                            if ((i == k) or (h == k)):
                                continue
                            else:
                                rounds += 1
                                # print(rounds)
                                opp_hand = [
                                    remaining_cards[j], remaining_cards[k]
                                ]
                                opp_score = evaluator.evaluate(
                                    temp_board_2, opp_hand)
                                score = evaluator.evaluate(temp_board_2, hand)
                                if (opp_score > score):
                                    wins += 1
                                # elif(evaluator.evaluate(board, opp_hand) < score):
                                #     loses += 1
                                elif (opp_score < score):
                                    draws += 1
        print("Rounds played: " + str(rounds) + " Wins: " + str(wins) +
              " Draws: " + str(draws))
        return (float(wins) / rounds) * 100.0
    else:
        print("ERROR")
Beispiel #9
0
# https://github.com/worldveil/deuces
# e.g. hole_cards = ['SA', 'C2'], community_cards = ['D9', 'H3', 'C5', 'S6', 'D4']
from Group02_card import Card
import Group02_evaluator
evaluator = Group02_evaluator.Evaluator()

all_cards = []
all_cards.append(Card.new('Ad'))
for i in xrange(8):
    all_cards.append(Card.new(str(i + 2) + 'd'))
all_cards.append(Card.new('Td'))
all_cards.append(Card.new('Jd'))
all_cards.append(Card.new('Qd'))
all_cards.append(Card.new('Kd'))

all_cards.append(Card.new('Ac'))
for i in xrange(8):
    all_cards.append(Card.new(str(i + 2) + 'c'))
all_cards.append(Card.new('Tc'))
all_cards.append(Card.new('Jc'))
all_cards.append(Card.new('Qc'))
all_cards.append(Card.new('Kc'))

all_cards.append(Card.new('Ah'))
for i in xrange(8):
    all_cards.append(Card.new(str(i + 2) + 'h'))
all_cards.append(Card.new('Th'))
all_cards.append(Card.new('Jh'))
all_cards.append(Card.new('Qh'))
all_cards.append(Card.new('Kh'))