Николай обнови решението на 26.03.2014 03:12 (преди над 10 години)
+from collections import OrderedDict
+
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return (self.symbol)
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ace')
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Two')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Three')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Four')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Five')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Six')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Seven')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Eight')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Nine')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ten')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Jack')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Queen')
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'King')
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return (self.color)
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Clubs')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Hearts')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Spades')
+
+
+RANKS = OrderedDict([('King', King), ('Queen', Queen), ('Jack', Jack),
+ ('Ten', Ten), ('Nine', Nine), ('Eight', Eight),
+ ('Seven', Seven), ('Six', Six), ('Five', Five),
+ ('Four', Four), ('Three', Three), ('Two', Two),
+ ('Ace', Ace)])
+
+SUITS = OrderedDict([('Diamonds', Diamonds), ('Clubs', Clubs),
+ ('Hearts', Hearts), ('Spades', Spades)])
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return ("{} of {}".format(self.rank, self.suit))
+
+ def __repr__(self):
+ return ("{} of {}".format(self.rank, self.suit))
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(-1)
+
+ 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 index(self, card):
+ return self.collection.index(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __str__(self):
+ return self.collection
+
+
+def CreateDeck(last_card=None):
+ deck_cards = []
+ for suit_key in SUITS:
+ for rank_key in RANKS:
+ if rank_key != last_card:
+ deck_cards.append(Card(RANKS[rank_key], SUITS[suit_key]))
+ else:
+ deck_cards.append(Card(RANKS["Ace"], SUITS[suit_key]))
+ break
+ return CardCollection(deck_cards)
+
+
+def StandardDeck():
+ return CreateDeck()
+
+
+def BeloteDeck():
+ return CreateDeck("Six")
+
+
+def SixtySixDeck():
+ return CreateDeck("Eight")