Решение на Тесте карти от Стоян Цветков

Обратно към всички решения

Към профила на Стоян Цветков

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

#========= Rank and subclasses =============
class Rank(object):
symbol = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.symbol
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Two(Rank):
symbol = 'Two'
class Three(Rank):
symbol = 'Three'
class Four(Rank):
symbol = 'Four'
class Five(Rank):
symbol = 'Five'
class Six(Rank):
symbol = 'Six'
class Seven(Rank):
symbol = 'Seven'
class Eight(Rank):
symbol = 'Eight'
class Nine(Rank):
symbol = 'Nine'
class Ten(Rank):
symbol = 'Ten'
class Jack(Rank):
symbol = 'Jack'
class Queen(Rank):
symbol = 'Queen'
class King(Rank):
symbol = 'King'
class Ace(Rank):
symbol = 'Ace'
#========== Suit and subclasses ===========
class Suit(object):
suit = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.suit
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Diamonds(Suit):
suit = 'Diamonds'
class Clubs(Suit):
suit = 'Clubs'
class Spades(Suit):
suit = 'Spades'
class Hearts(Suit):
suit = 'Hearts'
#=========== Constant suit/rank dicts ===========
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five,
'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
'Ace': Ace}
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs,
'Hearts': Hearts, 'Spades': Spades}
#============ Card/Deck classes ================
class Card(object):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return "{} of {}".format(str(self._rank), str(self._suit))
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
def __hash__(self):
"""To enable creating sets of Card instances."""
return 0
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
#ommiting setters to make class immutable
class CardCollection(object):
def __init__(self, collection=[]):
self.collection = list(collection)
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def __str__(self):
for card in self.collection:
print("<Card {}>".format(str(card)), end=" ")
print("\n")
return ""
def __repr__(self):
print("so repr, much info, wow!")
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
for i in range(len(self.collection)):
if self.collection[i] == card:
return i
else:
raise ValueError('could not find %r in deck' % (card))
#============ Deck generators ================
ORDER_OF_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Six',
'Five', 'Four', 'Three', 'Two', 'Ace']
#Generate a list of cards based on desired ranks/suits
DECKER = lambda suits, ranks: [Card(RANKS[rank], SUITS[suit]) for suit in suits
for rank in ranks]
def StandardDeck():
return CardCollection(DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS))
def SixtySixDeck():
ssdeck = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:])
return CardCollection(ssdeck)
def BeloteDeck():
belote = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:])
return CardCollection(belote)

Лог от изпълнението

................
----------------------------------------------------------------------
Ran 16 tests in 0.018s

OK

История (4 версии и 3 коментара)

Стоян обнови решението на 25.03.2014 00:39 (преди около 10 години)

+#Rank and subclasses
+class Rank(object):
+ symbol = None
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+ def __str__(self):
+ return self.symbol
+
+ def __repr__(self):
+ return '<%s.%s object at %s>' % (
+ self.__class__.__module__,
+ self.__class__.__name__,
+ hex(id(self)))
+
+class Two(Rank):
+ symbol = 'Two'
+
+class Three(Rank):
+ symbol = 'Three'
+
+class Four(Rank):
+ symbol = 'Four'
+
+class Five(Rank):
+ symbol = 'Five'
+
+class Six(Rank):
+ symbol = 'Six'
+
+class Seven(Rank):
+ symbol = 'Seven'
+
+class Eight(Rank):
+ symbol = 'Eight'
+
+class Nine(Rank):
+ symbol = 'Nine'
+
+class Ten(Rank):
+ symbol = 'Ten'
+
+class Jack(Rank):
+ symbol = 'Jack'
+
+class Queen(Rank):
+ symbol = 'Queen'
+
+class King(Rank):
+ symbol = 'King'
+
+class Ace(Rank):
+ symbol = 'Ace'
+
+#Suit and subclasses
+class Suit(object):
+ suit = None
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+ def __str__(self):
+ return self.suit
+
+ def __repr__(self):
+ return '<%s.%s object at %s>' % (
+ self.__class__.__module__,
+ self.__class__.__name__,
+ hex(id(self)))
+
+class Diamonds(Suit):
+ suit = 'Diamonds'
+
+class Clubs(Suit):
+ suit = 'Clubs'
+
+class Spades(Suit):
+ suit = 'Spades'
+
+class Hearts(Suit):
+ suit = 'Hearts'
+
+#Constant dicts
+RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five,
+ 'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
+ 'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
+ 'Ace': Ace}
+
+SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs,
+ 'Hearts': Hearts, 'Spades': Spades}
+
+#Card class
+class Card(object):
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ def __eq__(self, other):
+ return self._rank == other._rank and self._suit == other._suit
+
+ def __str__(self):
+ return "{} of {}".format(str(self._rank), str(self._suit))
+
+ def __repr__(self):
+ return '<%s.%s object at %s>' % (
+ self.__class__.__module__,
+ self.__class__.__name__,
+ hex(id(self)))
+
+ @property
+ def rank(self):
+ return self._rank #Rank.__repr__(self._rank)
+ #Don't know why it returns <builtins.type...> instead of
+ #<__main__.someRank...>
+
+ @property
+ def suit(self):
+ return self._suit #Suit.__repr__(self._suit)
+
+ #ommiting setters to make class immutable
+
+
+class CardCollection(object):
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __str__(self):
+ for card in self.collection:
+ print("<Card {}>".format(str(card)), end=" ")
+ print("\n")
+ return ""
+
+ def __repr__(self):
+ print("so repr, much info, wow!")
+
+ def draw(self, index):
+ card = self.collection[index]
+ del self.collection[index]
+ return card
+
+ def draw_from_top(self):
+ card = self.collection[-1]
+ del self.collection[-1]
+ return card
+
+ def draw_from_bottom(self):
+ card = self.collection[0]
+ del self.collection[0]
+ return card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ for i in range(len(self.collection)):
+ if self.collection[i] == card:
+ return i
+ else:
+ raise ValueError('could not find %r in deck' % (card))
+
+
+ORDER_OF_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
+ 'Nine', 'Eight', 'Seven', 'Six',
+ 'Five', 'Four', 'Three', 'Two', 'Ace']
+
+def StandardDeck():
+ std_deck = []
+ for suit in ORDER_OF_SUITS:
+ for rank in ORDER_OF_RANKS:
+ std_deck.append(Card(RANKS[rank], SUITS[suit]))
+ return CardCollection(std_deck)
+
+
+def SixtySixDeck():
+ ss_order_of_ranks = ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:]
+ ss_deck = []
+ for suit in ORDER_OF_SUITS:
+ for rank in ss_order_of_ranks:
+ ss_deck.append(Card(RANKS[rank], SUITS[suit]))
+ return CardCollection(ss_deck)
+
+
+def BeloteDeck():
+ belote_order_of_ranks = ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:]
+ belote_deck = []
+ for suit in ORDER_OF_SUITS:
+ for rank in belote_order_of_ranks:
+ belote_deck.append(Card(RANKS[rank], SUITS[suit]))
+ return CardCollection(belote_deck)

Стоян обнови решението на 26.03.2014 13:20 (преди около 10 години)

-#Rank and subclasses
+#========= Rank and subclasses =============
+
+
class Rank(object):
symbol = None
-
+
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.symbol
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
+
class Two(Rank):
symbol = 'Two'
+
class Three(Rank):
symbol = 'Three'
+
class Four(Rank):
symbol = 'Four'
+
class Five(Rank):
symbol = 'Five'
+
class Six(Rank):
symbol = 'Six'
+
class Seven(Rank):
symbol = 'Seven'
+
class Eight(Rank):
symbol = 'Eight'
+
class Nine(Rank):
symbol = 'Nine'
+
class Ten(Rank):
symbol = 'Ten'
+
class Jack(Rank):
symbol = 'Jack'
+
class Queen(Rank):
symbol = 'Queen'
+
class King(Rank):
symbol = 'King'
+
class Ace(Rank):
symbol = 'Ace'
-#Suit and subclasses
+#========== Suit and subclasses ===========
+
+
class Suit(object):
suit = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.suit
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
+
class Diamonds(Suit):
suit = 'Diamonds'
+
class Clubs(Suit):
suit = 'Clubs'
+
class Spades(Suit):
suit = 'Spades'
+
class Hearts(Suit):
suit = 'Hearts'
-#Constant dicts
+
+#=========== Constant suit/rank dicts ===========
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five,
'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
- 'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
+ 'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
'Ace': Ace}
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs,
'Hearts': Hearts, 'Spades': Spades}
-#Card class
-class Card(object):
+#============ Card/Deck classes ================
+
+
+class Card(object):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return "{} of {}".format(str(self._rank), str(self._suit))
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
@property
def rank(self):
- return self._rank #Rank.__repr__(self._rank)
- #Don't know why it returns <builtins.type...> instead of
- #<__main__.someRank...>
-
+ return self._rank
+
@property
def suit(self):
- return self._suit #Suit.__repr__(self._suit)
-
+ return self._suit
#ommiting setters to make class immutable
class CardCollection(object):
def __init__(self, collection=[]):
self.collection = collection
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def __str__(self):
for card in self.collection:
print("<Card {}>".format(str(card)), end=" ")
print("\n")
return ""
def __repr__(self):
print("so repr, much info, wow!")
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
-
+
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
for i in range(len(self.collection)):
if self.collection[i] == card:
return i
else:
raise ValueError('could not find %r in deck' % (card))
-
+#============ Deck generators ================
ORDER_OF_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
-ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
- 'Nine', 'Eight', 'Seven', 'Six',
+ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
+ 'Nine', 'Eight', 'Seven', 'Six',
'Five', 'Four', 'Three', 'Two', 'Ace']
+#Generate a list of cards based on desired ranks/suits
+DECKER = lambda suits, ranks: [Card(RANKS[rank], SUITS[suit]) for suit in suits
+ for rank in ranks]
+
+
def StandardDeck():
- std_deck = []
- for suit in ORDER_OF_SUITS:
- for rank in ORDER_OF_RANKS:
- std_deck.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(std_deck)
+ return CardCollection(DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS))
def SixtySixDeck():
- ss_order_of_ranks = ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:]
- ss_deck = []
- for suit in ORDER_OF_SUITS:
- for rank in ss_order_of_ranks:
- ss_deck.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(ss_deck)
+ #ss_order_of_ranks = ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:]
+ ssdeck = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:])
+ return CardCollection(ssdeck)
def BeloteDeck():
- belote_order_of_ranks = ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:]
- belote_deck = []
+ #belote_order_of_ranks = ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:]
- for suit in ORDER_OF_SUITS:
+ belote = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:])
- for rank in belote_order_of_ranks:
+ return CardCollection(belote)
- belote_deck.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(belote_deck)

Стоян обнови решението на 26.03.2014 13:42 (преди около 10 години)

#========= Rank and subclasses =============
class Rank(object):
symbol = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.symbol
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Two(Rank):
symbol = 'Two'
class Three(Rank):
symbol = 'Three'
class Four(Rank):
symbol = 'Four'
class Five(Rank):
symbol = 'Five'
class Six(Rank):
symbol = 'Six'
class Seven(Rank):
symbol = 'Seven'
class Eight(Rank):
symbol = 'Eight'
class Nine(Rank):
symbol = 'Nine'
class Ten(Rank):
symbol = 'Ten'
class Jack(Rank):
symbol = 'Jack'
class Queen(Rank):
symbol = 'Queen'
class King(Rank):
symbol = 'King'
class Ace(Rank):
symbol = 'Ace'
#========== Suit and subclasses ===========
class Suit(object):
suit = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.suit
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Diamonds(Suit):
suit = 'Diamonds'
class Clubs(Suit):
suit = 'Clubs'
class Spades(Suit):
suit = 'Spades'
class Hearts(Suit):
suit = 'Hearts'
#=========== Constant suit/rank dicts ===========
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five,
'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
'Ace': Ace}
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs,
'Hearts': Hearts, 'Spades': Spades}
#============ Card/Deck classes ================
class Card(object):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return "{} of {}".format(str(self._rank), str(self._suit))
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
+ def __hash__(self):
+ """To enable creating sets of Card instances."""
+
+ return 0
+
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
#ommiting setters to make class immutable
class CardCollection(object):
def __init__(self, collection=[]):
- self.collection = collection
+ self.collection = list(collection)
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def __str__(self):
for card in self.collection:
print("<Card {}>".format(str(card)), end=" ")
print("\n")
return ""
def __repr__(self):
print("so repr, much info, wow!")
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
for i in range(len(self.collection)):
if self.collection[i] == card:
return i
else:
raise ValueError('could not find %r in deck' % (card))
#============ Deck generators ================
ORDER_OF_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Six',
'Five', 'Four', 'Three', 'Two', 'Ace']
#Generate a list of cards based on desired ranks/suits
DECKER = lambda suits, ranks: [Card(RANKS[rank], SUITS[suit]) for suit in suits
for rank in ranks]
def StandardDeck():
return CardCollection(DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS))
def SixtySixDeck():
- #ss_order_of_ranks = ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:]
ssdeck = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:])
return CardCollection(ssdeck)
def BeloteDeck():
- #belote_order_of_ranks = ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:]
belote = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:])
- return CardCollection(belote)
+ return CardCollection(list(set(belote)))

Стоян обнови решението на 26.03.2014 13:44 (преди около 10 години)

#========= Rank and subclasses =============
class Rank(object):
symbol = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.symbol
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Two(Rank):
symbol = 'Two'
class Three(Rank):
symbol = 'Three'
class Four(Rank):
symbol = 'Four'
class Five(Rank):
symbol = 'Five'
class Six(Rank):
symbol = 'Six'
class Seven(Rank):
symbol = 'Seven'
class Eight(Rank):
symbol = 'Eight'
class Nine(Rank):
symbol = 'Nine'
class Ten(Rank):
symbol = 'Ten'
class Jack(Rank):
symbol = 'Jack'
class Queen(Rank):
symbol = 'Queen'
class King(Rank):
symbol = 'King'
class Ace(Rank):
symbol = 'Ace'
#========== Suit and subclasses ===========
class Suit(object):
suit = None
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.suit
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
class Diamonds(Suit):
suit = 'Diamonds'
class Clubs(Suit):
suit = 'Clubs'
class Spades(Suit):
suit = 'Spades'
class Hearts(Suit):
suit = 'Hearts'
#=========== Constant suit/rank dicts ===========
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five,
'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'King': King,
'Ace': Ace}
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs,
'Hearts': Hearts, 'Spades': Spades}
#============ Card/Deck classes ================
class Card(object):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return "{} of {}".format(str(self._rank), str(self._suit))
def __repr__(self):
return '<%s.%s object at %s>' % (
self.__class__.__module__,
self.__class__.__name__,
hex(id(self)))
def __hash__(self):
"""To enable creating sets of Card instances."""
return 0
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
#ommiting setters to make class immutable
class CardCollection(object):
def __init__(self, collection=[]):
self.collection = list(collection)
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def __str__(self):
for card in self.collection:
print("<Card {}>".format(str(card)), end=" ")
print("\n")
return ""
def __repr__(self):
print("so repr, much info, wow!")
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
for i in range(len(self.collection)):
if self.collection[i] == card:
return i
else:
raise ValueError('could not find %r in deck' % (card))
#============ Deck generators ================
ORDER_OF_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDER_OF_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Six',
'Five', 'Four', 'Three', 'Two', 'Ace']
#Generate a list of cards based on desired ranks/suits
DECKER = lambda suits, ranks: [Card(RANKS[rank], SUITS[suit]) for suit in suits
for rank in ranks]
def StandardDeck():
return CardCollection(DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS))
def SixtySixDeck():
ssdeck = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-8] + ORDER_OF_RANKS[-1:])
return CardCollection(ssdeck)
def BeloteDeck():
belote = DECKER(ORDER_OF_SUITS, ORDER_OF_RANKS[:-6] + ORDER_OF_RANKS[-1:])
- return CardCollection(list(set(belote)))
+ return CardCollection(belote)