Стоян обнови решението на 21.03.2014 17:50 (преди над 10 години)
+class Rank:
+
+ def __init__(self, symbol=''):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ for rank_name, rank_class in RANKS.items():
+ if rank_class == self.__class__:
+ return rank_name
+
+
+class Suit:
+
+ def __init__(self, color=''):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+ def __str__(self):
+ for suit_name, suit_class in SUITS.items():
+ if suit_class == self.__class__:
+ return suit_name
+
+
+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 __str__(self):
+ return str(self.__rank) + ' of ' + str(self.__suit)
+
+ def __eq__(self, other):
+ return str(self) == str(other)
+
+
+class CardCollection:
+
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def draw(self, index):
+ drawed_card = self.collection[index]
+ del self.collection[index]
+ return drawed_card
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ bottom_card = self.collection[0]
+ del self.collection[0]
+ return bottom_card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __iter__(self):
+ for card in self.collection:
+ yield card
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+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 Hearts(Suit):
+ color = 'red'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+class Spades(Suit):
+ color = 'black'
+
+ranks_name = ('King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace')
+ranks_class = (King, Queen, Jack, Ten, Nine, Eight,
+ Seven, Six, Five, Four, Three, Two, Ace)
+suits_name = ('Diamonds', 'Clubs', 'Hearts', 'Spades')
+suits_class = (Diamonds, Clubs, Hearts, Spades)
+
+RANKS = {rank: rank_class for rank, rank_class in zip(ranks_name, ranks_class)}
+SUITS = {suit: suit_class for suit, suit_class in zip(suits_name, suits_class)}
+
+
+def StandartDeck():
+ standart_deck = CardCollection([])
+ for suit_name in suits_name:
+ for rank_name in ranks_name:
+ standart_deck.add(Card(RANKS[rank_name], SUITS[suit_name]))
+ return standart_deck
+
+
+def BeloteDeck():
+ belote_deck = CardCollection([])
+ for suit_name in suits_name:
+ for rank_name in ranks_name[:7]:
+ belote_deck.add(Card(RANKS[rank_name], SUITS[suit_name]))
+ belote_deck.add(Card(RANKS["Ace"], SUITS[suit_name]))
+ return belote_deck
+
+
+def SixtySixDeck():
+ sixty_six_deck = CardCollection([])
+ for suit_name in suits_name:
+ for rank_name in ranks_name[:5]:
+ sixty_six_deck.add(Card(RANKS[rank_name], SUITS[suit_name]))
+ sixty_six_deck.add(Card(RANKS["Ace"], SUITS[suit_name]))
+ return sixty_six_deck