Веселин обнови решението на 25.03.2014 01:07 (преди над 10 години)
+from itertools import product
+
+
+class Rank:
+ def __init__(self):
+ self.symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.symbol
+
+
+class Suit:
+ def __init__(self):
+ self.color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.color
+
+
+RANK_NAMES = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+SUIT_NAMES = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+RANKS = {symbol: type(symbol, (Rank,), dict(symbol=symbol))
+ for symbol in RANK_NAMES}
+SUITS = {color: type(color, (Suit,), dict(color=color))
+ for color in SUIT_NAMES}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.properties = (rank(), suit())
+
+ @property
+ def rank(self):
+ return self.properties[0]
+
+ @property
+ def suit(self):
+ return self.properties[1]
+
+ def __eq__(self, other):
+ return str(self) == str(other)
+
+ def __str__(self):
+ return "{0} of {1}".format(self.properties[0], self.properties[1])
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ 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[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ self.collection.index(card)
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandardDeck():
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)]
+ return CardCollection(cards)
+
+
+def BeloteDeck():
+ excluded_ranks = ['Six', 'Five', 'Four', 'Three', 'Two']
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)
+ if rank not in excluded_ranks]
+ return CardCollection(cards)
+
+
+def SixtySixDeck():
+ excluded_ranks = ['Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two']
+ cards = [Card(RANKS[rank], SUITS[suit])
+ for rank, suit in product(RANK_NAMES, SUIT_NAMES)
+ if rank not in excluded_ranks]
+ return CardCollection(cards)