예제 #1
0
    def test_7card_rankings(self):
        for hand, rep in self._7CARD_HANDS:
            self.assertEqual(repr(poker.get_7_card_ranking(hand)), rep)
            # rotating the suits should always give an equal hand
            shuffled = self.clone_and_shuffle(hand)
            r1 = poker.get_7_card_ranking(hand)
            r2 = poker.get_7_card_ranking(shuffled)
            self.assertEqual(r1, r2)
            self.assertEqual(repr(r1), repr(r2))

        # compare hands with each other; later ones in the list are better than
        # earlier ones.
        for (h1, d1), (h2, d2) in itertools.combinations(self._7CARD_HANDS, 2):
            self.assertLess(poker.get_7_card_ranking(h1),
                            poker.get_7_card_ranking(h2))
예제 #2
0
파일: poker_tests.py 프로젝트: fdanbo/cards
    def test_7card_rankings(self):
        for hand, rep in self._7CARD_HANDS:
            self.assertEqual(repr(poker.get_7_card_ranking(hand)), rep)
            # rotating the suits should always give an equal hand
            shuffled = self.clone_and_shuffle(hand)
            r1 = poker.get_7_card_ranking(hand)
            r2 = poker.get_7_card_ranking(shuffled)
            self.assertEqual(r1, r2)
            self.assertEqual(repr(r1), repr(r2))

        # compare hands with each other; later ones in the list are better than
        # earlier ones.
        for (h1, d1), (h2, d2) in itertools.combinations(
                self._7CARD_HANDS, 2
        ):
            self.assertLess(poker.get_7_card_ranking(h1),
                            poker.get_7_card_ranking(h2))
예제 #3
0
파일: hi.py 프로젝트: fdanbo/cards
 def callback(event, index=None, amount=None):
     nonlocal signal
     interpreter.holdem_callback(event, index, amount)
     if event == 'showdown':
         for ps in interpreter.holdem.players:
             if not ps.folded:
                 if ((get_7_card_ranking(ps.hand).ranking ==
                      Ranking.straight_flush)):
                     signal = False
예제 #4
0
 def callback(event, index=None, amount=None):
     nonlocal signal
     interpreter.holdem_callback(event, index, amount)
     if event == 'showdown':
         for ps in interpreter.holdem.players:
             if not ps.folded:
                 if ((get_7_card_ranking(
                         ps.hand).ranking == Ranking.straight_flush)):
                     signal = False
예제 #5
0
 def event_showdown(self, player_state, amount):
     self.stdout.write('--------------------------------------------\n')
     self.stdout.write('SHOWDOWN!\n')
     # show what everyone had
     for ps in self.holdem.players:
         if not ps.folded:
             self.stdout.write('{} had [{}{}] -- {}\n'.format(
                 display.name(ps.name), display.cards(ps.hand[0]),
                 display.cards(ps.hand[1]),
                 display.cards(get_7_card_ranking(ps.hand))))
예제 #6
0
파일: holdem.py 프로젝트: fdanbo/cards
    def showdown(self):
        # assemble the poker hand objects
        players = [p for p in self.players if not p.folded]
        for p in players:
            for c in self.upcards:
                p.hand.append(c)

        # now find the highest
        highest = [players[0]]
        for p in players[1:]:
            if ((poker.get_7_card_ranking(p.hand) >
                 poker.get_7_card_ranking(highest[0].hand))):
                highest = [p]
            elif (poker.get_7_card_ranking(p.hand) ==
                  poker.get_7_card_ranking(highest[0].hand)):
                highest.append(p)

        self.callback('showdown')
        self.declare_winners([p.index for p in highest])
예제 #7
0
    def showdown(self):
        # assemble the poker hand objects
        players = [p for p in self.players if not p.folded]
        for p in players:
            for c in self.upcards:
                p.hand.append(c)

        # now find the highest
        highest = [players[0]]
        for p in players[1:]:
            if ((poker.get_7_card_ranking(p.hand) > poker.get_7_card_ranking(
                    highest[0].hand))):
                highest = [p]
            elif (poker.get_7_card_ranking(p.hand) == poker.get_7_card_ranking(
                    highest[0].hand)):
                highest.append(p)

        self.callback('showdown')
        self.declare_winners([p.index for p in highest])
예제 #8
0
파일: interactive.py 프로젝트: fdanbo/cards
 def event_showdown(self, player_state, amount):
     self.stdout.write('--------------------------------------------\n')
     self.stdout.write('SHOWDOWN!\n')
     # show what everyone had
     for ps in self.holdem.players:
         if not ps.folded:
             self.stdout.write('{} had [{}{}] -- {}\n'.format(
                 display.name(ps.name),
                 display.cards(ps.hand[0]),
                 display.cards(ps.hand[1]),
                 display.cards(get_7_card_ranking(ps.hand))
             ))
예제 #9
0
def random_sample_hands():
    # generate two of each type
    lists = {
        k: []
        for k in range(poker.Ranking.high_card, poker.Ranking.straight_flush +
                       1)
    }
    while True:
        deck = cards.Deck()
        hand = cards.Hand(deck.dealn(7))
        ranking = poker.get_7_card_ranking(hand)
        if len(lists[ranking.ranking]) < 2:
            print('{} {}'.format(hand.pretty(), ranking))
            lists[ranking.ranking].append(hand)
        if all(len(l) == 2 for l in lists.values()):
            break

    return sum(lists.values(), [])
예제 #10
0
#!/usr/bin/env python3

import cards
from poker import poker


def random_sample_hands():
    # generate two of each type
    lists = {
        k: []
        for k in range(poker.Ranking.high_card, poker.Ranking.straight_flush +
                       1)
    }
    while True:
        deck = cards.Deck()
        hand = cards.Hand(deck.dealn(7))
        ranking = poker.get_7_card_ranking(hand)
        if len(lists[ranking.ranking]) < 2:
            print('{} {}'.format(hand.pretty(), ranking))
            lists[ranking.ranking].append(hand)
        if all(len(l) == 2 for l in lists.values()):
            break

    return sum(lists.values(), [])


if __name__ == '__main__':
    hands = random_sample_hands()
    for hand in hands:
        print("('{}', '{}'".format(hand, poker.get_7_card_ranking(hand)))