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))
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))
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
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
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))))
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])
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])
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)) ))
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(), [])
#!/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)))