Божидар обнови решението на 26.03.2014 11:33 (преди над 10 години)
+from collections import deque
+
+ranks = {'Two': '2', 'Three': '3', 'Four': '4', 'Five': '5', 'Six': '6',
+ 'Seven': '7', 'Eight': '8', 'Nine': '9', 'Ten': '10', 'Jack': 'J',
+ 'Queen': 'Q', 'King': 'K', 'Ace': 'A'}
+suits = {'Hearts': 'red', 'Diamonds': 'red',
+ 'Clubs': 'black', 'Spades': 'black'}
+order_of_ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+order_of_suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+class Rank(object):
+ rank = ""
+ symbol = ""
+
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+ def __str__(self):
+ return self.rank
+
+
+class Suit(object):
+ suit = ""
+ color = ""
+
+ def __eq__(self, other):
+ return self.suit == other.suit
+
+ def __str__(self):
+ return self.suit
+
+
+class Card(object):
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection(object):
+ def __init__(self, collection):
+ self.deck = deque(collection)
+
+ def draw(self, index):
+ if index > len(self.deck):
+ raise IndexError
+
+ counter_cards = deque()
+ for i in range(index + 1):
+ counter_cards.append(self.deck.pop())
+
+ while(len(counter_cards) != 1):
+ self.deck.append(counter_cards.popleft())
+ return counter_cards.pop()
+
+ def draw_from_top(self):
+ return self.deck.pop()
+
+ def draw_from_bottom(self):
+ return self.deck.popleft()
+
+ def top_card(self):
+ return self.deck[-1]
+
+ def bottom_card(self):
+ return self.deck[0]
+
+ def add(self, card):
+ self.deck.append(card)
+
+ def index(self, card):
+ for i in range(len(self.deck)):
+ if self.deck[i] == card:
+ return i
+ raise ValueError
+
+ def __getitem__(self):
+ return self.deck.__getitem__()
+
+ def __iter__(self):
+ return self.deck.__iter__()
+
+
+def _create_rank_class(ranks, symb):
+ return type(ranks, (Rank,), dict(rank=ranks, symbol=symb))
+
+
+def _create_suit_class(suits, colors):
+ return type(suits, (Suit,), dict(suit=suits, color=colors))
+
+
+def _create_card_class(rank, suit):
+ return Card(rank, suit)
+
+
+RANKS = {rank: _create_rank_class(rank, ranks[rank]) for rank in ranks.keys()}
+SUITS = {suit: _create_suit_class(suit, suits[suit]) for suit in suits.keys()}
+
+
+def StandardDeck():
+ standard_deck = []
+ for suit in order_of_suits:
+ for rank in order_of_ranks:
+ standard_deck.append(_create_card_class(RANKS[rank], SUITS[suit]))
+
+ return standard_deck
+
+
+def BeloteDeck():
+ return [_create_card_class(RANKS[rank], SUITS[suit])
+ for suit in order_of_suits for rank in order_of_ranks
+ if int(ranks[rank], 32) not in range(2, 7)]
+
+
+def SixtySixDeck():
+ return [_create_card_class(RANKS[rank], SUITS[suit])
+ for suit in order_of_suits for rank in order_of_ranks
+ if int(ranks[rank], 32) not in range(2, 9)]