Венцислав обнови решението на 22.03.2014 03:00 (преди над 10 години)
+class Rank:
+ def __init__(self, rank=''):
+ self.rank = rank
+
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ def __init__(self, suit=''):
+ self.suit = suit
+
+ def __eq__(self, other):
+ return self.suit == other.suit
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+RANKS = {}
+SUITS = {}
+ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
+ 'Eight', 'Seven', 'Six', 'Five', 'Four',
+ 'Three', 'Two', 'Ace']
+ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+for r in ALL_RANKS:
+ RANKS[r] = type(r, (Rank,), {})
+
+
+for s in ALL_SUITS:
+ SUITS[s] = type(s, (Suit,), {})
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.__rank = rank
+ self.__suit = suit
+
+ def __str__(self):
+ return str(self.__rank()) + ' of ' + str(self.__suit())
+
+ def __repr__(self):
+ return '<Card ' + self.__str__() + '>'
+
+ def __eq__(self, other):
+ return self.__rank == other.__rank and self.__suit == other.__suit
+
+ @property
+ def rank(self):
+ return self.__rank()
+
+ @property
+ def suit(self):
+ return self.__suit()
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.cards = list(collection)
+
+ def __getitem__(self, index):
+ return self.cards[index]
+
+ def __len__(self):
+ return len(self.cards)
+
+ def draw(self, index):
+ return self.cards.pop(index)
+
+ def draw_from_top(self):
+ return self.cards.pop()
+
+ def draw_from_bottom(self):
+ return self.cards.pop(0)
+
+ def top_card(self):
+ return self.cards[len(self.cards) - 1]
+
+ def bottom_card(self):
+ return self.cards[0]
+
+ def add(self, card):
+ self.cards.append(card)
+
+ def index(self, card):
+ return self.cards.index(card)
+
+
+def StandardDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS]
+
+
+def BeloteDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:7] + ['Ace']]
+
+
+def SixtySixDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:5] + ['Ace']]