# hand.py
# Steve Marschner (srm2), Lillian Lee (ljl2), and Walker White
# October 15, 2014
"""Lecture Demo: class to represent poker hands"""
import card
import random

class Hand(object):
    """Instances represent a hand in poker.
    
    Instance Attributes:
        cards: cards in the hand [list of Card]
        
    This list is sorted according to the ordering defined by the 
    Card class."""

    def __init__(self, deck, n):
        """Initializer: Creates a hand of n cards.
        
        Parameter deck: The initital deck to draw from
        Precondition: deck is a list of >= n cards.  
        Deck is assumed to be shuffled.
        
        Parameter n: The number of cards to draw
        Precondition: n is an int >= 0
        """
        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):
        """Returns: True if this hand is a 5-card full house."""
        pass

    def is_flush(self):
        """Returns: True if this hand is a 5-card flush."""
        pass

    def is_pair(self):
        """Returns: True if this hand contains a pair."""
        pass

    def discard(self, k):
        """Discard the k-th card, counting from zero.
        
        Parameter k: the card to discard
        Precondition: Hand contains at least k+1 cards
        """
        pass

    def __str__(self):
        """Returns: A string representation of this hand."""
        return ', '.join(map(str, self.cards))


def demo_hand():
    """Show off hands in action"""
    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


if __name__ == '__main__':
    demo_hand()