Ангел обнови решението на 26.03.2014 16:19 (преди над 10 години)
+import collections
+
+
+class Rank:
+ symbol = ""
+
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __str__(self):
+ return str(self.symbol)
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __str__(self):
+ return str(self.color)
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Jack')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Queen')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'King')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ace')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Hearts')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Spades')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Clubs')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
+ 'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
+ 'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace}
+
+
+SUITS = {'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 __setattr__():
+ raise AttributeError("Киро не дава!!!")
+
+ def __str__(self):
+ return str(self.rank) + " of " + str(self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other. suit
+
+
+class CardCollection:
+ def __init__(self, collection=list()):
+ self.collection = list(collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __getitem__(self, index):
+ return (self.collection)[index]
+
+ 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 add(self, card):
+ return self.collection.append(card)
+
+ def index(self, card):
+ return card in self.collection
+
+
+def StandardDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Two', Two),
+ ('Three', Three),
+ ('Four', Four),
+ ('Five', Five),
+ ('Six', Six),
+ ('Seven', Seven),
+ ('Eight', Eight),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)
+
+
+def BeloteDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Seven', Seven),
+ ('Eight', Eight),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)
+
+
+def SixtySixDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)