コード例 #1
0
ファイル: test.py プロジェクト: yangrq1018/texas_holdem
 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}')
コード例 #2
0
ファイル: test.py プロジェクト: yangrq1018/texas_holdem
 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}')
コード例 #3
0
ファイル: test.py プロジェクト: yangrq1018/texas_holdem
    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))
コード例 #4
0
ファイル: deck.py プロジェクト: yangrq1018/texas_holdem
 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
コード例 #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
コード例 #6
0
ファイル: test.py プロジェクト: yangrq1018/texas_holdem
 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
コード例 #7
0
ファイル: test.py プロジェクト: yangrq1018/texas_holdem
 def test_card(self):
     print([TexasCard.from_str(s) for s in ('As', '2c', '3d', '5s', '4c')])