Решение на Тесте карти от Стефан Колчев

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

Към профила на Стефан Колчев

Резултати

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

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return type(self).__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return type(self).__name__ == type(other).__name__
def __str__(self):
return type(self).__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
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')
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 = {'Hearts': Hearts, 'Clubs': Clubs,
'Spades': Spades, 'Diamonds': Diamonds}
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.suit == other.suit and self.rank == other.rank
def __str__(self):
return '{} of {}'.format(str(self.rank), str(self.suit))
def __repr__(self):
return str(self)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
__delattr__ = __setattr__
class CardCollection:
def __init__(self, collection=[]):
self.collection = [card for card in collection]
def __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def __iter__(self):
return iter(self.collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.draw(len(self.collection) - 1)
def draw_from_bottom(self):
return self.draw(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 StandardDeck():
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
ORDERED_RANKS]
return CardCollection(deck)
def BeloteDeck():
belote_ranks = ORDERED_RANKS[0:7]
belote_ranks.append('Ace')
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
belote_ranks]
return CardCollection(deck)
def SixtySixDeck():
sixty_six_ranks = ORDERED_RANKS[0:5]
sixty_six_ranks.append('Ace')
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
sixty_six_ranks]
return CardCollection(deck)

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.023s

OK

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

Стефан обнови решението на 26.03.2014 13:07 (преди над 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return type(self).__name__ == type(other).__name__
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+
+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')
+
+
+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 = {'Hearts': Hearts, 'Clubs': Clubs,
+ 'Spades': Spades, 'Diamonds': Diamonds}
+
+
+ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __eq__(self, other):
+ return self.suit == other.suit and self.rank == other.rank
+
+ def __str__(self):
+ return '{} of {}'.format(str(self.rank), str(self.suit))
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.draw(len(self.collection) - 1)
+
+ def draw_from_bottom(self):
+ return self.draw(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 StandardDeck():
+ deck = [Card(RANKS[r], SUITS[s]) for r in ORDERED_RANKS for s in
+ ORDERED_SUITS]
+ return CardCollection(deck)
+
+
+def BeloteDeck():
+ belote_ranks = ORDERED_RANKS[0:6]
+ belote_ranks.append('Ace')
+ deck = [Card(RANKS[r], SUITS[s]) for r in belote_ranks for s in
+ ORDERED_SUITS]
+ return CardCollection(deck)
+
+
+def SixtySixDeck():
+ sixty_six_ranks = ORDERED_RANKS[0:5]
+ sixty_six_ranks.append('Ace')
+ deck = [Card(RANKS[r], SUITS[s]) for r in sixty_six_ranks for s in
+ ORDERED_SUITS]
+ return CardCollection(deck)

Стефан обнови решението на 26.03.2014 15:01 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return type(self).__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return type(self).__name__ == type(other).__name__
def __str__(self):
return type(self).__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
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')
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 = {'Hearts': Hearts, 'Clubs': Clubs,
'Spades': Spades, 'Diamonds': Diamonds}
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.suit == other.suit and self.rank == other.rank
def __str__(self):
return '{} of {}'.format(str(self.rank), str(self.suit))
+ def __repr__(self):
+ return str(self)
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+ __delattr__ = __setattr__
+
+
class CardCollection:
def __init__(self, collection=[]):
self.collection = collection
def __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
+ def __iter__(self):
+ return iter(self.collection)
+
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.draw(len(self.collection) - 1)
def draw_from_bottom(self):
return self.draw(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 StandardDeck():
- deck = [Card(RANKS[r], SUITS[s]) for r in ORDERED_RANKS for s in
- ORDERED_SUITS]
+ deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
+ ORDERED_RANKS]
return CardCollection(deck)
def BeloteDeck():
- belote_ranks = ORDERED_RANKS[0:6]
+ belote_ranks = ORDERED_RANKS[0:7]
belote_ranks.append('Ace')
- deck = [Card(RANKS[r], SUITS[s]) for r in belote_ranks for s in
- ORDERED_SUITS]
+ deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
+ belote_ranks]
return CardCollection(deck)
def SixtySixDeck():
sixty_six_ranks = ORDERED_RANKS[0:5]
sixty_six_ranks.append('Ace')
- deck = [Card(RANKS[r], SUITS[s]) for r in sixty_six_ranks for s in
- ORDERED_SUITS]
+ deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
+ sixty_six_ranks]
return CardCollection(deck)

Стефан обнови решението на 26.03.2014 16:11 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return type(self).__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return type(self).__name__ == type(other).__name__
def __str__(self):
return type(self).__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
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')
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 = {'Hearts': Hearts, 'Clubs': Clubs,
'Spades': Spades, 'Diamonds': Diamonds}
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.suit == other.suit and self.rank == other.rank
def __str__(self):
return '{} of {}'.format(str(self.rank), str(self.suit))
def __repr__(self):
return str(self)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
__delattr__ = __setattr__
class CardCollection:
def __init__(self, collection=[]):
- self.collection = collection
+ self.collection = [card for card in collection]
def __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def __iter__(self):
return iter(self.collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.draw(len(self.collection) - 1)
def draw_from_bottom(self):
return self.draw(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 StandardDeck():
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
ORDERED_RANKS]
return CardCollection(deck)
def BeloteDeck():
belote_ranks = ORDERED_RANKS[0:7]
belote_ranks.append('Ace')
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
belote_ranks]
return CardCollection(deck)
def SixtySixDeck():
sixty_six_ranks = ORDERED_RANKS[0:5]
sixty_six_ranks.append('Ace')
deck = [Card(RANKS[r], SUITS[s]) for s in ORDERED_SUITS for r in
sixty_six_ranks]
return CardCollection(deck)