Евгени обнови решението на 20.03.2014 21:41 (преди над 10 години)
+import collections
+
+
+class CommonMixin:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __lt__(self, other):
+ return self.order < other.order
+
+
+class Rank(CommonMixin):
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+
+class Two(Rank):
+ def __init__(self):
+ self.rank = '2'
+ self.order = 2
+
+
+class Three(Rank):
+ def __init__(self):
+ self.rank = '3'
+ self.order = 3
+
+
+class Four(Rank):
+ def __init__(self):
+ self.rank = '4'
+ self.order = 4
+
+
+class Five(Rank):
+ def __init__(self):
+ self.rank = '5'
+ self.order = 5
+
+
+class Six(Rank):
+ def __init__(self):
+ self.rank = '6'
+ self.order = 6
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.rank = '7'
+ self.order = 7
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.rank = '8'
+ self.order = 8
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.rank = '9'
+ self.order = 9
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.rank = '10'
+ self.order = 10
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.rank = 'J'
+ self.order = 11
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.rank = 'Q'
+ self.order = 12
+
+
+class King(Rank):
+ def __init__(self):
+ self.rank = 'K'
+ self.order = 13
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.rank = 'A'
+ self.order = 1
+
+
+class Suit(CommonMixin):
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = 'red'
+ self.order = 4
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = 'black'
+ self.order = 3
+
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = 'red'
+ self.order = 2
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = 'black'
+ self.order = 1
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+ def __eq__(self, other):
+ return (self.rank, self.suit) == (other.rank, other.suit)
+
+ def __str__(self):
+ return "{} of {}".format(self.rank, self.suit)
+
+ def __repr__(self):
+ return "<Card {}>".format(self)
+
+ def __lt__(self, other):
+ return (self.suit, self.rank) < (other.suit, other.rank)
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = collections.deque(collection)
+
+ def draw(self, index):
+ card = self.collection[index]
+ self.collection.remove(card)
+ return card
+
+ def draw_from_bottom(self):
+ return self.collection.popleft()
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def index(self, card):
+ return list(self.collection).index(card)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+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,
+ 'Spades': Spades,
+ 'Hearts': Hearts,
+ 'Clubs': Clubs,
+}
+
+
+def StandardDeck():
+ return list(sorted((
+ Card(rank, suit)
+ for rank in RANKS.values()
+ for suit in SUITS.values()
+ ), reverse=True))
+
+
+def BeloteDeck():
+ return list(sorted((
+ Card(rank, suit)
+ for rank in RANKS.values()
+ for suit in SUITS.values()
+ if rank not in [Two, Three, Four, Five, Six]
+ ), reverse=True))
+
+
+def SixtySixDeck():
+ return list(sorted((
+ Card(rank, suit)
+ for rank in RANKS.values()
+ for suit in SUITS.values()
+ if rank not in [Two, Three, Four, Five, Six, Seven, Eight]
+ ), reverse=True))
Много си работлив! Не знам защо ти е конструктор на всеки клас за боя и карта, може да са атрибути :) И що не филтрираш резултатите от StandardDeck за останалите тестета?