<commit_before>import random
import itertools


class Shuffle(object):
    """
    Class for setting up the deck and 
    accessing cards.
    """
    def __init__(self):
        self.suits = ['heart','diamond','spade','club'] * 13
        self.cards = {'deuce':2,'three':3,'four':4,'five':5,'six':6,'seven':7,
                      'eight':8,'nine':9,'ten':10,'jack':10,'queen':10,'king':10,'ace':11}
        # creates a six deck with the suits and cards variables # 
        self.deck = list(itertools.izip(self.suits,self.cards.keys() * 4)) * 6
        # shuffles the decks to randomize them #
        random.shuffle(self.deck)
        return


class Deal(Shuffle):
    """
    Class that handles passing cards to dealer or
    player when called.
    """ 
    def __init__(self):
        Shuffle.__init__(self)
        # when Deal class is called the player hand pops the first two of the deck #
        self.player = self.deck.pop(0) + self.deck.pop(1)
        # Just one for the dealer hand #
        self.dealer = self.deck.pop(0)       


class Take(Shuffle):
    """
    Class for 'hit'ing a player/dealer
    when asked for.
    """
    def card(self):
        # when 'hit' button is clicked pygames events trigger Take() #
        # player grabs first #
        self.card = self.deck[0]
        self.deck.pop(0) 
        return self.card


class Total(Shuffle):
    """
    Class that will score a hand.
    """
    def tally(self,score):
        self.amount = 0
        for i in score:
            # Total() takes the hands 'cards' and matches the key in the deck #
            if self.cards.has_key(i):
                self.amount += self.cards[i]
        # This conditional will check for the best possible hand with aces #
        if self.amount > 21 and 'ace' in score:
            for i in range(score.count('ace')):
                if self.amount > 21:
                    self.amount -= 10
        return self.amount


class Hold(Total):
    """
    Class to call when all players
    are done taking cards.
    """
    def dealer_hit(self,score):
        comp = self.tally(score)
        # blackjack rules dealer must take cards while under 17 #
        if comp > 16:
            return    
        if comp < 17:
            self.card = self.deck[0]
            self.deck.pop(0)
            return self.card

<commit_msg>restructure<commit_after>import random
import itertools


SUITS = ['heart','diamond','spade','club'] * 13
CARDS = {'deuce':2, 'three':3, 'four':4, 'five':5,
         'six':6, 'seven':7, 'eight':8,'nine':9, 'ten':10, 
         'jack':10, 'queen':10, 'king':10, 'ace':11}

def deal():
    deck = list(itertools.izip(SUITS, CARDS.keys() * 4)) * 6
    random.shuffle(deck)
    player = deck.pop(0) + deck.pop(1)
    dealer = deck.pop(0)       
    return deck

def take():
    deck = deal()
    card = deck[0]
    deck.pop(0) 
    return card


def total(score):
    amount = 0
    for i in score:
        if CARDS.has_key(i):
            amount += CARDS[i]
    if amount > 21 and 'ace' in score:
        for i in range(score.count('ace')):
            if amount > 21:
                amount -= 10
    return amount

def hold(score):
    comp = total(score)
    if comp > 16:
        return    
    if comp < 17:
        card = deck[0]
        deck.pop(0)
        return card

{'fraction_non_alphanumeric': 0.12979172955025656, 'fraction_numerical': 0.024750980984002413, 'mean_word_length': 1.993676603432701, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2075752', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1029, 'n_words': 304}