Александър обнови решението на 25.03.2014 00:56 (преди над 10 години)
+class ClassNameRepresenter:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return str(self) == str(other)
+
+
+class Rank(ClassNameRepresenter):
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+
+class Suit(ClassNameRepresenter):
+ def __init__(self, color):
+ self.color = color
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+RANKS = {'King': King, 'Six': Six, 'Jack': Jack, 'Five': Five, 'Queen': Queen,
+ 'Ten': Ten, 'Ace': Ace, 'Three': Three, 'Eight': Eight, 'Four': Four,
+ 'Two': Two, 'Seven': Seven, 'Nine': Nine}
+
+
+SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
+ 'Spades': Spades, 'Clubs': Clubs}
+
+
+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 "{0} of {1}".format(str(self.rank), str(self.suit))
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.__cards = []
+ for card in collection:
+ self.add(card)
+
+ def draw(self, index):
+ return self.__cards.pop(index)
+
+ def draw_from_top(self):
+ return self.__cards.pop(len(self.__cards) - 1)
+
+ 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):
+ cards_count = len(self.__cards)
+ for i in range(0, cards_count):
+ if self.__cards[i] == card:
+ return i
+ raise ValueError('Cound not find the specified card.')
+
+ def __getitem__(self, index):
+ return self.__cards[index]
+
+ def __len__(self):
+ return len(self.__cards)
+
+
+SUITS_ORDERED = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+RANKS_ORDERED = [
+ 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace'
+]
+
+
+def generate_deck(ranks_to_filter=set()):
+ cards = CardCollection([])
+ for suit in SUITS_ORDERED:
+ for rank in RANKS_ORDERED:
+ if rank not in ranks_to_filter:
+ cards.add(Card(RANKS[rank], SUITS[suit]))
+ return cards
+
+
+def StandardDeck():
+ return generate_deck()
+
+
+def BeloteDeck():
+ return generate_deck({'Two', 'Three', 'Four', 'Five', 'Six'})
+
+
+def SixtySixDeck():
+ return generate_deck({
+ 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'
+ })