Иван обнови решението на 23.03.2014 01:32 (преди над 10 години)
+from collections import OrderedDict
+
+
+SYMBOLS = OrderedDict([('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 = OrderedDict([('Diamonds', 'red'), ('Clubs', 'black'),
+ ('Hearts', 'red'), ('Spades', 'black')])
+
+
+class Rank:
+ def __init__(self, rank_of_card):
+ self.rank_of_card = rank_of_card
+ self.symbol = SYMBOLS[rank_of_card]
+
+ def __eq__(self, other):
+ return self.rank_of_card == other.rank_of_card
+
+ def __str__(self):
+ return str(self.rank_of_card)
+
+
+class Suit:
+ def __init__(self, suit_of_card):
+ self.suit_of_card = suit_of_card
+ self.color = COLORS[suit_of_card]
+
+ def __eq__(self, other):
+ return self.suit_of_card == other.suit_of_card
+
+ def __str__(self):
+ return str(self.suit_of_card)
+
+
+class Two(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Two')
+
+
+class Three(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Three')
+
+
+class Four(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Four')
+
+
+class Five(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Five')
+
+
+class Six(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Six')
+
+
+class Seven(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Seven')
+
+
+class Eight(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Eight')
+
+
+class Nine(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Nine')
+
+
+class Ten(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Ten')
+
+
+class Jack(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Jack')
+
+
+class Queen(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Queen')
+
+
+class King(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'King')
+
+
+class Ace(Rank):
+ def __init__(self):
+ return Rank.__init__(self, 'Ace')
+
+
+class Spades(Suit):
+ def __init__(self):
+ return Suit.__init__(self, 'Spades')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ return Suit.__init__(self, 'Hearts')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ return Suit.__init__(self, 'Clubs')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ return Suit.__init__(self, 'Diamonds')
+
+
+RANKS = OrderedDict([('King', type(King())), ('Queen', type(Queen())),
+ ('Jack', type(Jack())), ('Ten', type(Ten())),
+ ('Nine', type(Nine())), ('Eight', type(Eight())),
+ ('Seven', type(Seven())), ('Six', type(Six())),
+ ('Five', type(Five())), ('Four', type(Four())),
+ ('Three', type(Three())), ('Two', type(Two())),
+ ('Ace', type(Ace()))])
+
+
+SUITS = OrderedDict([('Diamonds', type(Diamonds())), ('Clubs', type(Clubs())),
+ ('Hearts', type(Hearts())), ('Spades', type(Spades()))])
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __eq__(self, other):
+ return [self.rank, self.suit] == [other.rank, other.suit]
+
+ def __str__(self):
+ return '{0} of {1}'.format(str(self.rank), str(self.suit))
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.deck = list(collection)
+
+ def __getitem__(self, index):
+ return self.deck[index]
+
+ def __len__(self):
+ return len(self.deck)
+
+ def __str__(self):
+ return str(self.deck)
+
+ def add(self, card):
+ self.deck.append(card)
+
+ def draw(self, index):
+ return self.deck.pop(index)
+
+ def draw_from_top(self):
+ return self.deck.pop(-1)
+
+ def draw_from_bottom(self):
+ return self.deck.pop(0)
+
+ def top_card(self):
+ return self.deck[-1]
+
+ def bottom_card(self):
+ return self.deck[0]
+
+ def index(self, card):
+ return self.deck.index(card)
+
+
+def StandardDeck():
+ return CardCollection([str(Card(rank, suit)) for suit in SUITS.values()
+ for rank in RANKS.values()])
+
+
+def BeloteDeck():
+ deck = StandardDeck()
+ first_half = deck.deck[:7] + deck.deck[12:20] + deck.deck[25:33]
+ second_half = deck.deck[38:46] + deck.deck[51:52]
+ return CardCollection(first_half + second_half)
+
+
+def SixtySixDeck():
+ deck = StandardDeck()
+ first_half = deck.deck[:5] + deck.deck[12:18] + deck[25:31]
+ second_half = deck.deck[38:44] + deck.deck[51:52]
+ return CardCollection(first_half + second_half)