Решение на Тесте карти от Йордан Дикманов

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

Към профила на Йордан Дикманов

Резултати

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

Код

class Rank:
def __init__(self, card_value):
self.symbol = card_value
def __eq__(self, right):
return self.symbol == right.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, suit):
self.color = suit
def __eq__(self, right):
return str(self) == str(right)
def __str__(self):
return self.__class__.__name__
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
RANKS = {'Six': Six, 'Four': Four, 'King': King,
'Jack': Jack, 'Five': Five, 'Queen': Queen,
'Ten': Ten, 'Three': Three, 'Eight': Eight,
'Two': Two, 'Seven': Seven, 'Nine': Nine,
'Ace': Ace}
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
'Clubs': Clubs, 'Spades': Spades}
class Card:
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __repr__(self):
return '<Card ' + str(self.rank) + ' of ' + str(self.suit) + '>'
def __eq__(self, right):
return str(self) == str(right)
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
class CardCollection:
def __init__(self, collection=[]):
self.card_collection = list(collection)
def draw(self, index):
if index < len(self.card_collection):
return self.card_collection.pop(index)
else:
return self.card_collection[index]
def draw_from_top(self):
return self.card_collection.pop(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.card_collection[-1]
def bottom_card(self):
return self.card_collection[0]
def add(self, card):
self.card_collection.append(card)
def index(self, card):
return self.card_collection.index(card)
def __getitem__(self, i):
return self.card_collection[i]
def __len__(self):
return len(self.card_collection)
def __repr__(self):
return '[' + ', '.join([repr(i) for i in self]) + ']'
def __iter__(self):
return iter(self.card_collection)
STANDART_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
STANDART_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
NOT_IN_BELOTE = ['Two', 'Three', 'Four', 'Five', 'Six']
NOTE_IN_SIXTYSIX = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
def StandardDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS
if card_rank not in NOT_IN_BELOTE])
def SixtySixDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS
if card_rank not in NOTE_IN_SIXTYSIX])

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.022s

OK

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

Йордан обнови решението на 23.03.2014 03:32 (преди над 10 години)

+class Rank:
+ def __init__(self, card_value):
+ self.symbol = card_value
+
+ def __eq__(self, right):
+ return self.symbol == right.symbol
+
+
+class Suit:
+ def __init__(self, suit):
+ self.color = suit
+
+ def __eq__(self, right):
+ return self.color == right.color
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __str__(self):
+ return 'Six'
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __str__(self):
+ return 'Four'
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+ def __str__(self):
+ return 'King'
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+ def __str__(self):
+ return 'Jack'
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __str__(self):
+ return 'Five'
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+ def __str__(self):
+ return 'Queen'
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __str__(self):
+ return 'Ten'
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __str__(self):
+ return 'Three'
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __str__(self):
+ return 'Eight'
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __str__(self):
+ return 'Two'
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __str__(self):
+ return 'Seven'
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __str__(self):
+ return 'Nine'
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+ def __str__(self):
+ return 'Ace'
+
+RANKS = {'Six': Six, 'Four': Four, 'King': King,
+ 'Jack': Jack, 'Five': Five, 'Queen': Queen,
+ 'Ten': Ten, 'Three': Three, 'Eight': Eight,
+ 'Two': Two, 'Seven': Seven, 'Nine': Nine,
+ 'Ace': Ace}
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return 'Hearts'
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return 'Clubs'
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return 'Spades'
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return 'Diamonds'
+
+
+SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
+ 'Clubs': Clubs, 'Spades': Spades}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+ def __repr__(self):
+ return '<' + str(self.rank) + ' of ' + str(self.suit) + '>'
+
+ def __eq__(self, right):
+ return str(self) == str(right)
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.card_collection = collection
+
+ def draw(self, index):
+ if index < len(self.card_collection):
+ return self.card_collection.pop(index)
+ else:
+ return self.card_collection[index]
+
+ def draw_from_top(self):
+ return self.card_collection.pop(-1)
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+ def top_card(self):
+ return self.card_collection[-1]
+
+ def bottom_card(self):
+ return self.card_collection[0]
+
+ def add(self, card):
+ self.card_collection.append(card)
+
+ def index(self, card):
+ return self.card_collection.index(card)
+
+ def __getitem__(self, i):
+ return self.card_collection[i]
+
+ def __setitem__(self, i, value):
+ self.card_collection[i] = value
+
+ def __len__(self):
+ return len(self.card_collection)
+
+
+def StandardDeck():
+ collection = []
+ for card_suit in SUITS:
+ for card_rank in RANKS:
+ collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
+ return collection
+
+NOT_IN_BELOTE = ['Two', 'Three', 'Four', 'Five', 'Six']
+
+NOTE_IN_SIXTYSIX = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
+
+
+def BeloteDeck():
+ collection = []
+ for card_suit in SUITS:
+ for card_rank in RANKS:
+ if card_rank not in NOT_IN_BELOTE:
+ collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
+ return collection
+
+
+def SixtySixDeck():
+ collection = []
+ for card_suit in SUITS:
+ for card_rank in RANKS:
+ if card_rank not in NOTE_IN_SIXTYSIX:
+ collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
+ return collection

Подредбата на стандартните тестета ти е различна всеки път като си пуснеш програмата. Пробвай! ;)

Иначе решението ти е ОК, но вместо да пишеш няколко вложени for-a и if-ове можеш да ползваш list comprehension.

Йордан обнови решението на 25.03.2014 00:16 (преди над 10 години)

class Rank:
def __init__(self, card_value):
self.symbol = card_value
def __eq__(self, right):
return self.symbol == right.symbol
+ def __str__(self):
+ return self.__class__.__name__
+
class Suit:
def __init__(self, suit):
self.color = suit
def __eq__(self, right):
return self.color == right.color
+ def __str__(self):
+ return self.__class__.__name__
+
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
- def __str__(self):
- return 'Six'
-
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
- def __str__(self):
- return 'Four'
-
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
- def __str__(self):
- return 'King'
-
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
- def __str__(self):
- return 'Jack'
-
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
- def __str__(self):
- return 'Five'
-
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
- def __str__(self):
- return 'Queen'
-
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
- def __str__(self):
- return 'Ten'
-
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
- def __str__(self):
- return 'Three'
-
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
- def __str__(self):
- return 'Eight'
-
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
- def __str__(self):
- return 'Two'
-
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
- def __str__(self):
- return 'Seven'
-
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
- def __str__(self):
- return 'Nine'
-
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
- def __str__(self):
- return 'Ace'
-
RANKS = {'Six': Six, 'Four': Four, 'King': King,
'Jack': Jack, 'Five': Five, 'Queen': Queen,
'Ten': Ten, 'Three': Three, 'Eight': Eight,
'Two': Two, 'Seven': Seven, 'Nine': Nine,
'Ace': Ace}
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
- def __str__(self):
- return 'Hearts'
-
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
- def __str__(self):
- return 'Clubs'
-
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
- def __str__(self):
- return 'Spades'
-
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
- def __str__(self):
- return 'Diamonds'
-
SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
'Clubs': Clubs, 'Spades': Spades}
class Card:
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __repr__(self):
return '<' + str(self.rank) + ' of ' + str(self.suit) + '>'
def __eq__(self, right):
return str(self) == str(right)
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
class CardCollection:
def __init__(self, collection=[]):
self.card_collection = collection
def draw(self, index):
if index < len(self.card_collection):
return self.card_collection.pop(index)
else:
return self.card_collection[index]
def draw_from_top(self):
return self.card_collection.pop(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.card_collection[-1]
def bottom_card(self):
return self.card_collection[0]
def add(self, card):
self.card_collection.append(card)
def index(self, card):
return self.card_collection.index(card)
def __getitem__(self, i):
return self.card_collection[i]
- def __setitem__(self, i, value):
- self.card_collection[i] = value
-
def __len__(self):
return len(self.card_collection)
-def StandardDeck():
- collection = []
- for card_suit in SUITS:
- for card_rank in RANKS:
- collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
- return collection
+STANDART_DACK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+STANDART_DACK_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
+
NOT_IN_BELOTE = ['Two', 'Three', 'Four', 'Five', 'Six']
NOTE_IN_SIXTYSIX = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
+def StandardDeck():
+ return [Card(RANKS[card_rank], SUITS[card_suit])
+ for card_suit in STANDART_DACK_SUITS
+ for card_rank in STANDART_DACK_RANKS]
+
+
def BeloteDeck():
- collection = []
- for card_suit in SUITS:
- for card_rank in RANKS:
- if card_rank not in NOT_IN_BELOTE:
- collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
- return collection
+ return [Card(RANKS[card_rank], SUITS[card_suit])
+ for card_suit in STANDART_DACK_SUITS
+ for card_rank in STANDART_DACK_RANKS
+ if card_rank not in NOT_IN_BELOTE]
def SixtySixDeck():
- collection = []
- for card_suit in SUITS:
+ return [Card(RANKS[card_rank], SUITS[card_suit])
- for card_rank in RANKS:
+ for card_suit in STANDART_DACK_SUITS
- if card_rank not in NOTE_IN_SIXTYSIX:
+ for card_rank in STANDART_DACK_RANKS
- collection.append(Card(RANKS[card_rank], SUITS[card_suit]))
+ if card_rank not in NOTE_IN_SIXTYSIX]
- return collection

Йордан обнови решението на 25.03.2014 21:09 (преди над 10 години)

class Rank:
def __init__(self, card_value):
self.symbol = card_value
def __eq__(self, right):
return self.symbol == right.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, suit):
self.color = suit
def __eq__(self, right):
return self.color == right.color
def __str__(self):
return self.__class__.__name__
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
RANKS = {'Six': Six, 'Four': Four, 'King': King,
'Jack': Jack, 'Five': Five, 'Queen': Queen,
'Ten': Ten, 'Three': Three, 'Eight': Eight,
'Two': Two, 'Seven': Seven, 'Nine': Nine,
'Ace': Ace}
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
'Clubs': Clubs, 'Spades': Spades}
class Card:
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __repr__(self):
- return '<' + str(self.rank) + ' of ' + str(self.suit) + '>'
+ return '<Card ' + str(self.rank) + ' of ' + str(self.suit) + '>'
def __eq__(self, right):
return str(self) == str(right)
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
class CardCollection:
def __init__(self, collection=[]):
- self.card_collection = collection
+ self.card_collection = list(collection)
def draw(self, index):
if index < len(self.card_collection):
return self.card_collection.pop(index)
else:
return self.card_collection[index]
def draw_from_top(self):
return self.card_collection.pop(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.card_collection[-1]
def bottom_card(self):
return self.card_collection[0]
def add(self, card):
self.card_collection.append(card)
def index(self, card):
return self.card_collection.index(card)
def __getitem__(self, i):
return self.card_collection[i]
def __len__(self):
return len(self.card_collection)
+ def __repr__(self):
+ return '[' + ', '.join([repr(i) for i in self]) + ']'
-STANDART_DACK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+STANDART_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
-STANDART_DACK_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
+STANDART_DECK_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
NOT_IN_BELOTE = ['Two', 'Three', 'Four', 'Five', 'Six']
NOTE_IN_SIXTYSIX = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
def StandardDeck():
- return [Card(RANKS[card_rank], SUITS[card_suit])
- for card_suit in STANDART_DACK_SUITS
- for card_rank in STANDART_DACK_RANKS]
+ return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
+ for card_suit in STANDART_DECK_SUITS
+ for card_rank in STANDART_DECK_RANKS])
def BeloteDeck():
- return [Card(RANKS[card_rank], SUITS[card_suit])
- for card_suit in STANDART_DACK_SUITS
- for card_rank in STANDART_DACK_RANKS
- if card_rank not in NOT_IN_BELOTE]
+ return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
+ for card_suit in STANDART_DECK_SUITS
+ for card_rank in STANDART_DECK_RANKS
+ if card_rank not in NOT_IN_BELOTE])
def SixtySixDeck():
- return [Card(RANKS[card_rank], SUITS[card_suit])
- for card_suit in STANDART_DACK_SUITS
+ return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
- for card_rank in STANDART_DACK_RANKS
+ for card_suit in STANDART_DECK_SUITS
- if card_rank not in NOTE_IN_SIXTYSIX]
+ for card_rank in STANDART_DECK_RANKS
+ if card_rank not in NOTE_IN_SIXTYSIX])

Йордан обнови решението на 26.03.2014 02:47 (преди над 10 години)

class Rank:
def __init__(self, card_value):
self.symbol = card_value
def __eq__(self, right):
return self.symbol == right.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, suit):
self.color = suit
def __eq__(self, right):
- return self.color == right.color
+ return str(self) == str(right)
def __str__(self):
return self.__class__.__name__
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
RANKS = {'Six': Six, 'Four': Four, 'King': King,
'Jack': Jack, 'Five': Five, 'Queen': Queen,
'Ten': Ten, 'Three': Three, 'Eight': Eight,
'Two': Two, 'Seven': Seven, 'Nine': Nine,
'Ace': Ace}
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
'Clubs': Clubs, 'Spades': Spades}
class Card:
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __repr__(self):
return '<Card ' + str(self.rank) + ' of ' + str(self.suit) + '>'
def __eq__(self, right):
return str(self) == str(right)
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
class CardCollection:
def __init__(self, collection=[]):
self.card_collection = list(collection)
def draw(self, index):
if index < len(self.card_collection):
return self.card_collection.pop(index)
else:
return self.card_collection[index]
def draw_from_top(self):
return self.card_collection.pop(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.card_collection[-1]
def bottom_card(self):
return self.card_collection[0]
def add(self, card):
self.card_collection.append(card)
def index(self, card):
return self.card_collection.index(card)
def __getitem__(self, i):
return self.card_collection[i]
def __len__(self):
return len(self.card_collection)
def __repr__(self):
return '[' + ', '.join([repr(i) for i in self]) + ']'
+ def __iter__(self):
+ return iter(self.card_collection)
+
STANDART_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
-STANDART_DECK_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
+STANDART_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
NOT_IN_BELOTE = ['Two', 'Three', 'Four', 'Five', 'Six']
NOTE_IN_SIXTYSIX = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
def StandardDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS
if card_rank not in NOT_IN_BELOTE])
def SixtySixDeck():
return CardCollection([Card(RANKS[card_rank], SUITS[card_suit])
for card_suit in STANDART_DECK_SUITS
for card_rank in STANDART_DECK_RANKS
if card_rank not in NOTE_IN_SIXTYSIX])