Антония обнови решението на 26.03.2014 15:50 (преди над 10 години)
+import collections
+
+class Rank:
+
+ def __init__(self, typeOfCards, symbol):
+ self.typeOfCards = typeOfCards
+ self.symbol = symbol
+
+ def __repr__(self):
+ return self.typeOfCards
+
+ def __eq__(self, first):
+ if self.typeOfCards == first.typeOfCards:
+ return True
+ else:
+ return False
+
+class Ace(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ace', 'A')
+
+class Two(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Two', '2')
+
+class Three(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Three', '3')
+
+class Four(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Four', '4')
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Five', '5')
+
+class Six(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Six', '6')
+
+class Seven(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Seven', '7')
+
+class Eight(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Eight', '8')
+
+class Nine(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Nine', '9')
+
+class Ten(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ten', '10')
+
+class Jack(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Jack', 'J')
+
+class Queen(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Queen', 'Q')
+
+class King(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'King', 'k')
+
+RANKS = {'Ace': Ace, 'Two': Two, 'Three': Three, 'Five': Five, 'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
+ 'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'Four': Four, 'King': King}
+
+class Suit:
+
+ def __init__(self, paint, color):
+ self.paint = paint
+ self.color = color
+
+ def __repr__(self):
+ return self.paint
+
+ def __eq__(self, first):
+ if self.paint == first.paint:
+ return True
+ else:
+ return False
+
+class Hearts(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Hearts', 'red')
+
+class Clubs(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Clubs', 'black')
+
+class Spades(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Spades', 'black')
+
+class Diamonds(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds', 'red')
+
+SUITS = {'Diamonds': Diamonds, 'Spades': Spades, 'Hearts': Hearts, 'Clubs': Clubs}
+
+class Card:
+
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __repr__(self):
+ return '{0} of {1}'.format(self.rank.typeOfCards, self.suit.paint)
+
+ def __eq__(self, first):
+ if self.rank == first.rank and self.suit == first.suit:
+ return True
+ return False
+
+class CardCollection(collections.Iterable):
+
+ def __init__(self, collection = []):
+ self.collection = list(collection)
+ self.next_index = 0
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ self.next_index += 1
+ if(self.next_index < len(self.collection)):
+ return self.collection[self.next_index]
+ else:
+ raise StopIteration
+
+
+ def draw(self, index):
+ removed_item = self.collection[index]
+ self.collection.remove(self.collection[index])
+ return removed_item
+
+ def draw_from_top(self):
+ return self.draw(len(self.collection) - 1)
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+ def top_card(self):
+ return self.collection[len(self.collection) - 1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def index(self, card):
+ for item in self.collection:
+ if card == item:
+ return self.collection.index(card)
+ raise ValueError
+
+ def __repr__(self):
+ return (str(list([str(item) for item in self.collection])))
+
+def StandardDeck():
+ deck = CardCollection()
+ deck.add(list(Card(rank, suit) for suit in SUITS.values()
+ for rank in RANKS.values()))
+ return deck
+
+
+def BeloteDeck():
+ pass
+
+def SixtySixDeck():
+ pass