Ивайло обнови решението на 26.03.2014 02:52 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.symbol
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.color
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+RANKS = {'King': King, 'Queen': Queen, 'Jack': Jack, 'Ten': Ten, 'Nine': Nine,
+ 'Eight': Eight, 'Seven': Seven, 'Six': Six, 'Five': Five,
+ 'Four': Four, 'Three': Three, 'Two': Two, 'Ace': Ace}
+SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
+
+
+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 str(self.__rank) == str(other.__rank) and \
+ str(self.__suit) == str(other.__suit)
+
+
+class CardCollection:
+ cards = list()
+
+ def __init__(self, collection=[]):
+ iterator = iter(collection)
+ for card in iterator:
+ self.cards.append(card)
+
+ 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[-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)
+
+
+ORDERED_RANKS = ["Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
+ "Six", "Five", "Four", "Three", "Two", "Ace"]
+ORDERED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
+
+
+def StandardDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS)
+
+
+def BeloteDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:8])
+
+
+def SixtySixDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:6])