Антонио обнови решението на 26.03.2014 01:55 (преди над 10 години)
+class Rank:
+ symbol = None
+
+ def __eq__(self, other):
+ return isinstance(self, type(other))
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+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}
+
+
+class Suit:
+ color = None
+
+ def __eq__(self, other):
+ return isinstance(self, type(other))
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+SUITS = {'Hearts': Hearts, 'Clubs': Clubs,
+ 'Spades': Spades, 'Diamonds': Diamonds}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+ def __eq__(self, other):
+ return self.rank == other.rank and other.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank) + " of " + str(self.suit)
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+ def top_card(self):
+ return self[-1]
+
+ def bottom_card(self):
+ return self[0]
+
+ def index(self, card):
+ for index, sheet in enumerate(self):
+ if str(sheet) == str(card):
+ return index
+ raise ValueError("<Card {}> is not in list".format(str(card)))
+
+ def __len__(self):
+ return len(self.collection)
+
+
+STANDARD_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+STANDARD_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+BELOTE_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Ace']
+SIXTY_SIX_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+
+
+def StandardDeck():
+ standard_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in STANDARD_DECK_RANKS:
+ standard_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return standard_deck
+
+
+def BeloteDeck():
+ belote_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in BELOTE_DECK_RANKS:
+ belote_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return belote_deck
+
+
+def SixtySixDeck():
+ sixty_six_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in SIXTY_SIX_DECK_RANKS:
+ sixty_six_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return sixty_six_deck