Аделина обнови решението на 26.03.2014 16:21 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = '2'
+ super(Two, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Two, self).__str__()
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = '3'
+ super(Three, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Three, self).__str__()
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = '4'
+ super(Four, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Four, self).__str__()
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = '5'
+ super(Five, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Five, self).__str__()
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = '6'
+ super(Six, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Six, self).__str__()
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = '7'
+ super(Seven, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Seven, self).__str__()
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = '8'
+ super(Eight, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Eight, self).__str__()
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = '9'
+ super(Nine, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Nine, self).__str__()
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = '10'
+ super(Ten, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Ten, self).__str__()
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = 'J'
+ super(Jack, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Jack, self).__str__()
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = 'Q'
+ super(Queen, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Queen, self).__str__()
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = 'K'
+ super(King, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(King, self).__str__()
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = 'A'
+ super(Ace, self).__init__(self.symbol)
+
+ def __str__(self):
+ return super(Ace, self).__str__()
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.suit == other.suit
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.suit = 'Diamonds'
+
+
+class Hearts(Suit):
+ def __init__(self):
+ self.suit = 'Hearts'
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.suit = 'Spades'
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.suit = 'Clubs'
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return (self.rank == other.rank and
+ self.suit == other.suit)
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
+
+ def draw(self, index):
+ card = self.collection[index]
+ self.collection.remove(card)
+ return card
+
+ def draw_from_top(self):
+ return draw(self, len(self.collection) - 1)
+
+ def draw_from_bottom(self):
+ return draw(self, 0)
+
+ def top_card(self):
+ return self.collection[len(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 __getitem__(self, i):
+ return self.collection[i]
+
+
+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}
+BELOTE_CARDS = ['King', 'Jack', 'Queen', 'Ten', 'Ace', 'Eight', 'Seven', 'Nine']
+SIXTY_SIX_CARDS = ['King', 'Jack', 'Queen', 'Ten', 'Ace', 'Nine']