Димитър обнови решението на 24.03.2014 23:21 (преди над 10 години)
+#from collections import OrderedDict
+SYMBOLS = {'King': 'K', 'Queen': 'Q', 'Jack': 'J', 'Ten': '10',
+ 'Nine': '9', 'Eight': '8', 'Seven': '7', 'Six': '6',
+ 'Five': '5', 'Four': '4', 'Three': '3', 'Two': '2',
+ 'Ace': 'A'}
+COLORS = {'Diamonds': 'black', 'Hearts': 'red',
+ 'Spades': 'black', 'Clubs': 'red'}
+
+
+class Rank:
+
+ def __init__(self):
+ self.symbol = SYMBOLS[self.__class__.__name__]
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+
+ def __init__(self):
+ self.color = COLORS[self.__class__.__name__]
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+ def __str__(self):
+ return self.__class__.__name__
+
+ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+RANKS = {key: type(key, (Rank,), {}) for key in ORDERED_RANKS}
+ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+SUITS = {key: type(key, (Suit,), {}) for key in ORDERED_SUITS}
+
+
+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 __getattr__(self, name):
+ return self.name
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+ def __repr__(self):
+ return '<class ' + str(self) + '>'
+
+
+class CardCollection:
+
+ def __init__(self, collection=[]):
+ self.cards = list(collection)
+
+ def draw(self, index):
+ return self.cards.pop(index)
+
+ def draw_from_top(self):
+ return self.cards.pop()
+
+ def draw_from_bottom(self):
+ return self.cards.pop(0)
+
+ def bottom_card(self):
+ return self.cards[0]
+
+ def top_card(self):
+ return self.cards[len(self.cards) - 1]
+
+ def add(self, card):
+ self.cards.append(card)
+
+ def index(self, card):
+ return self.cards.index(card)
+
+ def __getitem__(self, index):
+ return self.cards[index]
+
+ def __len__(self):
+ return len(self.cards)
+
+
+def StandardDeck():
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS for rank in ORDERED_RANKS]
+
+
+def BeloteDeck():
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS for rank in ORDERED_RANKS[0:7] + ['Ace']]
+
+
+def SixtySixDeck():
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS for rank in ORDERED_RANKS[0:5] + ['Ace']]