Skip to content

Instantly share code, notes, and snippets.

@phamd1989
Created February 14, 2014 20:54
Show Gist options
  • Save phamd1989/9009045 to your computer and use it in GitHub Desktop.
Save phamd1989/9009045 to your computer and use it in GitHub Desktop.
Homework for SigFig
import random
class Card(object):
suits = {'C':'Club', 'D':'Diamond', 'H':'Heart', 'S':'Spade'}
ranks = {1:'Ace', 11:'Jack', 12:'Queen', 13:'King'}
def __init__(self, rank, suit):
# go from 1 to 13
self.rank = rank
# 4 types of suit: Club, Diamond, Heart, Spade
self.suit = suit
def __repr__(self):
rank = self.ranks.get(self.rank, str(self.rank))
suit = self.suits.get(self.suit)
return '<%s of %s>' % (rank, suit)
def value(self):
# different card game have a different way to value a card
raise NotImplementedError("Please implement this method for your card game")
class Deck(object):
def __init__(self):
self.deck = []
for i in range(1,14):
for j in Card.suits.items():
self.deck.append(Card(i, j[0]))
def deal_card(self):
if len(self.deck) != 0:
random.shuffle(self.deck)
return self.deck.pop()
return None
class Hand(Card):
def __init__(self):
self.cards = []
def score(self):
# find score for this hand of cards
score = 0
for card in self.cards:
score += card.value()
return score
def add_card(self, card):
self.cards.append(card)
class GenericGamePlay(object):
def __init__(self):
self.deck = Deck()
def score(self):
# different card game have a different way to score a card
raise NotImplementedError("Please implement this method for your card game")
def winner(self, hand1, hand2):
# figure out the winner among two hands of cards
raise NotImplementedError("Please implement this method for your card game")
# c = Card(5, 'D')
# d = Deck()
# for i in range(52):
# print d.deal_card()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment