Спасимир обнови решението на 26.03.2014 16:57 (преди над 10 години)
+from collections import OrderedDict
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, "A")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Ace"
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self,"2")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Two"
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self,"3")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Three"
+
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, "4")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Four"
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, "5")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Five"
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, "6")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+ def __str__(self):
+ return "Six"
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, "7")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Seven"
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, "8")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Eight"
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, "9")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Nine"
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, "10")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Ten"
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, "J")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Jack"
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, "Q")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Queen"
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self,"K")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "King"
+
+
+RANKS2 = 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)])
+
+RANKS = {'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}
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+
+ def __str__(self):
+ return "Diamonds"
+
+
+class Spades(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"black")
+
+ def __str__(self):
+ return "Spades"
+
+
+class Clubs(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"black")
+
+ def __str__(self):
+ return "Clubs"
+
+
+class Hearts(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"red")
+
+ def __str__(self):
+ return "Hearts"
+
+SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
+SUITS2 = OrderedDict([('Diamonds', Diamonds), ('Clubs', Clubs), ('Hearts', Hearts), ('Spades', Spades)])
+
+
+class Card:
+
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(self, "suit", suit())
+
+ def __setattr__(self, key, value):
+ raise AttributeError("can't set attribute")
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return '{} of {}'.format(self.rank, self.suit)
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
+
+ def __getitem__(self, i):
+ return (self.collection)[i]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ temp = self.collection[index]
+ self.collection.pop(index)
+
+ def draw_from_bottom(self):
+ temp = self.collection[0]
+ self.collection.pop(0)
+ return temp
+
+ def draw_from_top(self):
+ bottom_index = len(self.collection)
+ result = self.collection[bottom_index]
+ self.collection.pop[bottom_index]
+ return result
+
+ def top_card(self):
+ return self.collection[len(self.collection)]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def index(self, searched_card):
+ counter = 0
+ for i in self.collection:
+ counter += 1
+ if(i == searched_card):
+ return counter
+ raise ValueError("<{}> is not in list".format(str(searched_card)))
+
+
+def StandardDeck():
+ temp = list()
+ for suit in SUITS2:
+ for rank in RANKS2:
+ temp.append(Card(RANKS2[str(rank)],SUITS2[str(suit)]))
+ return CardCollection(temp)