Гергана обнови решението на 21.03.2014 16:46 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = 'K'
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = '6'
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = 'J'
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = '5'
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = 'Q'
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = '10'
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = 'A'
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = '3'
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = '8'
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = '4'
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = '2'
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = '7'
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = '9'
+
+
+RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
+ [King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight, Four, Two, Seven, Nine]))
+
+
+class Suit:
+ def __init__(self, colour):
+ self.color = colour
+
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = 'red'
+
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = 'red'
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = 'black'
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = 'black'
+
+
+SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'], [Diamonds, Hearts, Spades, Clubs]))
+
+
+class Card(Rank, Suit):
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+
+ def __str__(self):
+ return '%s of %s' % (self.rank, self.suit)
+
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+ def __setattr_(self, *args):
+ raise AttributeError
+
+class CardCollection:
+ def __init__(self, collection = []):
+ self.deck = collection
+
+
+ def __getitem__(self, index):
+ return self.deck[index]
+
+
+ def __len__(self):
+ return len(self.deck)
+
+
+ def draw(self, index):
+ card = self[index]
+ self.deck.remove(card)
+ return card
+
+
+ def draw_from_top(self):
+ return self.draw(len(self) - 1)
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+
+ def top_card(self):
+ return self.deck[len(self) - 1]
+
+
+ def bottom_card(self):
+ return self.deck[0]
+
+
+ def add(self, card):
+ self.deck.append(card)
+
+
+ def index(self, card):
+ return self.deck.index(card)