Esempio n. 1
0
 def test_histogram(self):
     hole_cards_p1 = (TexasCard.from_str('As'), TexasCard.from_str('Ac'))
     hole_cards_p2 = (TexasCard.from_str('7c'), TexasCard.from_str('8d'))
     board = Deck().pop(*hole_cards_p1, *hole_cards_p2).pool
     result = histogram(hole_cards_p1, board)
     for k, v in result.items():
         print(f'{k:<13} : {v:.9f}')
Esempio n. 2
0
 def test_showdown_decision(self):
     hole_cards = (TexasCard.from_str('5h'), TexasCard.from_str('Th'))
     community_cards = Deck().pop(*hole_cards).deal(5)
     print(f'Hole cards: {hole_cards}')
     print(f'Community cards: {community_cards}')
     best = decide_showdown(hole_cards + community_cards)
     print('Best play -->')
     print(f'5 card picked: {best.cards()}')
     print(f'The type is \n {best}')
Esempio n. 3
0
    def test_deck(self):
        all_cards = Deck.gen_poker()
        # print(all_cards)
        self.assertTrue(len(all_cards) == 52)

        deck = Deck()
        hole_card1 = TexasCard.from_str('7h')
        hole_card2 = TexasCard.from_str('9s')
        # remove two cards
        removed = deck.pop(hole_card1, hole_card2)
        self.assertTrue(len(removed.pool) == 52 - 2)
        print(deck.deal(5))
Esempio n. 4
0
 def gen_poker():
     """
     :return: a list of 52 poker cards, excluding the Jokers
     """
     cards = []
     for s, r in itertools.product(list(Suit), list(Rank)):
         cards.append(TexasCard(s, r))
     return cards
Esempio n. 5
0
def decide_showdown(table_cards: Iterable[TexasCard], assist=True):
    """
    If table cards have duplicates, the eval7 implementation might go wrong!
    so check for it
    @param table_cards: five to seven cards
    @return:
    """
    if len(set(table_cards)) < len(tuple(table_cards)):
        raise ValueError('Duplicated cards')
    table_cards: List[TexasCard] = TexasCard.sort_desc(table_cards)
    hand = [eval7.Card(c.to_eval7_str()) for c in table_cards]
    int_type = eval7.evaluate(hand)
    str_type = eval7.handtype(int_type)
    best_type = STR_MAP[str_type]

    if assist and best_type == StraightFlush:
        # check with my implementation
        best = detect.decide_showdown(table_cards)
        assert isinstance(best, StraightFlush) or isinstance(best, RoyalFlush)
        if best.__class__ == RoyalFlush:
            best_type = RoyalFlush
    return best_type
Esempio n. 6
0
 def showdown(string: str):
     cards = [TexasCard.from_str(s) for s in string.split(' ')]
     hole_cards = tuple(cards[:2])
     community_cards = tuple(cards[2:])
     result = eval7_decide_showdown(hole_cards + community_cards)
     return result
Esempio n. 7
0
 def test_card(self):
     print([TexasCard.from_str(s) for s in ('As', '2c', '3d', '5s', '4c')])