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

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

Към профила на Стоян Христов

Резултати

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

Код

class Rank:
symbol = ''
def __eq__(self, other):
return self.__class__ == other.__class__
def __repr__(self):
return self.__class__.__name__
class Suit:
color = ''
def __eq__(self, other):
return self.__class__ == other.__class__
def __repr__(self):
return self.__class__.__name__
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
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, 'Hearts': Hearts,
'Spades': Spades, 'Clubs': Clubs}
class Card:
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 __repr__(self):
return '{0} of {1}'.format(str(self.rank), str(self.suit))
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def __getitem__(self, index):
return self.collection[index]
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __len__(self):
return len(self.collection)
def __repr__(self):
return ', '.join(['Card ' + str(card) for card in self.collection])
ORDERED_RANKS = (King, Queen, Jack, Ten, Nine, Eight, Seven,
Six, Five, Four, Three, Two, Ace)
ORDERED_SUITS = (Diamonds, Clubs, Hearts, Spades)
def CreateDeck(not_included):
deck = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank not in not_included:
deck.append(Card(rank, suit))
return CardCollection(deck)
def StandardDeck():
return CreateDeck([])
def BeloteDeck():
return CreateDeck([Six, Five, Four, Three, Two])
def SixtySixDeck():
return CreateDeck([Eight, Seven, Six, Five, Four, Three, Two])

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.020s

OK

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

Стоян обнови решението на 23.03.2014 15:59 (преди около 10 години)

+
+
+class Rank:
+ symbol = ''
+
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+ def __repr__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ color = ''
+
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+ def __repr__(self):
+ return self.__class__.__name__
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+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, 'Hearts': Hearts,
+ 'Spades': Spades, 'Clubs': Clubs}
+
+
+class Card:
+
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __repr__(self):
+ return '{0} of {1}'.format(str(self.rank), str(self.suit))
+
+ def __setattr__(self, name, value):
+ raise TypeError('can\'t set attribute')
+
+
+class CardCollection:
+
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[len(self.collection) - 1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __repr__(self):
+ return ', '.join(['Card ' + str(card) for card in self.collection])
+
+
+ORDERED_RANKS = (King, Queen, Jack, Ten, Nine, Eight, Seven,
+ Six, Five, Four, Three, Two, Ace)
+ORDERED_SUITS = (Diamonds, Clubs, Hearts, Spades)
+
+
+def CreateDeck(not_included):
+ deck = []
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
+ if rank not in not_included:
+ deck.append(Card(rank, suit))
+
+ return CardCollection(deck)
+
+
+def StandardDeck():
+ return CreateDeck([])
+
+
+def BeloteDeck():
+ return CreateDeck([Six, Five, Four, Three, Two])
+
+
+def SixtySixDeck():
+ return CreateDeck([Eight, Seven, Six, Five, Four, Three, Two])

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

class Rank:
symbol = ''
def __eq__(self, other):
return self.__class__ == other.__class__
def __repr__(self):
return self.__class__.__name__
class Suit:
color = ''
def __eq__(self, other):
return self.__class__ == other.__class__
def __repr__(self):
return self.__class__.__name__
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
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, 'Hearts': Hearts,
'Spades': Spades, 'Clubs': Clubs}
class Card:
def __init__(self, rank, suit):
- object.__setattr__(self, 'rank', rank())
- object.__setattr__(self, 'suit', suit())
+ self._rank = rank()
+ self._suit = suit()
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __repr__(self):
return '{0} of {1}'.format(str(self.rank), str(self.suit))
-
- def __setattr__(self, name, value):
- raise TypeError('can\'t set attribute')
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def __getitem__(self, index):
return self.collection[index]
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __len__(self):
return len(self.collection)
def __repr__(self):
return ', '.join(['Card ' + str(card) for card in self.collection])
ORDERED_RANKS = (King, Queen, Jack, Ten, Nine, Eight, Seven,
Six, Five, Four, Three, Two, Ace)
ORDERED_SUITS = (Diamonds, Clubs, Hearts, Spades)
def CreateDeck(not_included):
deck = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank not in not_included:
deck.append(Card(rank, suit))
return CardCollection(deck)
def StandardDeck():
return CreateDeck([])
def BeloteDeck():
return CreateDeck([Six, Five, Four, Three, Two])
def SixtySixDeck():
return CreateDeck([Eight, Seven, Six, Five, Four, Three, Two])