# hand.py # Steve Marschner (srm2) and Lillian Lee (ljl2) # March 13, 2013 """Lecture demo: class to represent poker hands. """ import card import random class Hand(object): """Instances represent a hand in poker. Instance variables: cards [list of Card]: cards in the hand This list is sorted according to the ordering defined by the Card class. """ def __init__(self, deck, n): """Draw a hand of n cards. Pre: deck is a list of >= n cards. Deck is shuffled. """ self.cards = [] for i in range(n): self.cards.append(deck.pop(0)) self.cards.sort() # #cards = deck[0:n] #deck[0:n] = [] def is_full_house(self): """Return: True if this hand is a 5-card full house.""" pass def is_flush(self): """Return: True if this hand is a 5-card flush.""" pass def is_pair(self): """Return: True if this hand contains a pair.""" pass def discard(self, k): """Discard the k-th card, counting from zero. Precondition: Hand contains at least k+1 cards """ pass def __str__(self): return ', '.join(map(str, self.cards)) if __name__ == '__main__': print Hand(card.full_deck(), 5) num_flushes = 0 num_full_houses = 0 num_pairs = 0 for i in range(1000): deck = card.full_deck() random.shuffle(deck) h = Hand(deck, 5) if h.is_full_house(): print 'full house:', h num_full_houses += 1 if h.is_flush(): print 'flush:', h num_flushes += 1 if h.is_pair(): print 'pair:', h num_pairs += 1 print num_full_houses, 'full houses; ', num_flushes, 'flushes; ', num_pairs, 'pairs'