Иван обнови решението на 25.03.2014 23:05 (преди над 10 години)
+from collections import OrderedDict
+
+STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
+ 'Eight', 'Seven', 'Six', 'Five', 'Four',
+ 'Three', 'Two', 'Ace',
+ ]
+FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
+ 'Nine', 'Eight', 'Seven', 'Ace',
+ ]
+
+SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+
+
+class Rank:
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return str(self.__class__.__name__)
+
+
+class Suit:
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return str(self.__class__.__name__)
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
+ ('Five', Five), ('Queen', Queen), ('Ten', Ten),
+ ('Ace', Ace), ('Three', Three), ('Eight', Eight),
+ ('Four', Four), ('Two', Two), ('Seven', Seven),
+ ('Nine', Nine),
+ ])
+SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
+ ('Spades', Spades), ('Clubs', Clubs),
+ ])
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank.__class__.__name__,
+ self.suit.__class__.__name__
+ )
+
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = collection
+ self.length = len(collection)
+ self.num = 0
+
+ def __getitem__(self, i):
+ return (self.collection)[i]
+
+ def __iter__(self):
+ while self.num < self.length:
+ yield self.collection[self.num]
+ self.num = self.num + 1
+
+ def add(self, card):
+ self.collection.append(card)
+ self.length = self.length + 1
+
+ def bottom_card(self):
+ return self.collection[self.num]
+
+ def top_card(self):
+ return self.collection[self.length-1]
+
+ def draw(self, index):
+ temporary = self.collection[index]
+ del self.collection[index]
+ self.length = self.length - 1
+ return temporary
+
+ def draw_from_top(self):
+ temporary = self.collection[self.length-1]
+ del self.collection[self.length-1]
+ self.length = self.length - 1
+ return temporary
+
+ def draw_from_bottom(self):
+ temporary = self.collection[self.num]
+ del self.collection[self.num]
+ self.length = self.length - 1
+ return temporary
+
+ def index(self, card):
+ if card in self.collection:
+ return self.collection.index(card)
+ else:
+ raise ValueError(str(card), ' is not in list')
+
+ def __len__(self):
+ return self.length
+
+
+def StandardDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in STANDARTDECK_ORDERED_RANKS:
+ collection.append(Card(rank, suit))
+ return CardCollection(collection)
+
+
+def BeloteDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in BELOTEDECK_ORDERED_RANKS:
+ collection.appends(Card(rank, suit))
+ return CardCollection(collection)
+
+
+def SixtySixDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in SIXTYSIXDECK_ORDERED_RANKS:
+ collection.append(Card(rank, suit))
+ return CardCollection(collection)