Александър обнови решението на 26.03.2014 16:21 (преди над 10 години)
+class Rank():
+ symbol = None
+ name = None
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.name
+
+class Suit():
+ color = None
+ name = None
+
+ def __eq__(self, other):
+ return self.colour == other.colour
+
+ def __str__(self):
+ return self.name
+
+
+
+class Ace(Rank):
+ symbol = 'A'
+ name = 'Ace'
+
+class King(Rank):
+ symbol = 'K'
+ name = 'King'
+
+class Queen(Rank):
+ symbol = 'Q'
+ name = 'Queen'
+
+class Jack(Rank):
+ symbol = 'J'
+ name = 'Jack'
+
+class Ten(Rank):
+ symbol = '10'
+ name = 'Ten'
+
+class Nine(Rank):
+ symbol = '9'
+ name = 'Nine'
+
+class Eight(Rank):
+ symbol = '8'
+ name = 'Eight'
+
+class Seven(Rank):
+ symbol = '7'
+ name = 'Seven'
+
+class Six(Rank):
+ symbol = '6'
+ name = 'Six'
+
+class Five(Rank):
+ symbol = '5'
+ name = 'Five'
+
+class Four(Rank):
+ symbol = '4'
+ name = 'Four'
+
+class Three(Rank):
+ symbol = '3'
+ name = 'Three'
+
+class Two(Rank):
+ symbol = '2'
+ name = 'Two'
+
+class Spades(Suit):
+ colour = 'black'
+ name = 'Spades'
+
+class Diamonds(Suit):
+ colour = 'red'
+ name = 'Diamonds'
+
+class Hearts(Suit):
+ colour = 'red'
+ name = 'Hearts'
+
+class Clubs(Suit):
+ colour = 'black'
+ name = 'Clubs'
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return (str(self.rank) + ' of ' + str(self.suit))
+
+ def __repr__(self):
+ return str('<Card ' + str(self) + '>')
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
+
+ def __getitem__(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection[index]
+
+ def draw(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection.pop[index]
+
+ def draw_from_top(self):
+ return self.collection.pop[len(collection)-1]
+
+ def draw_from_bottom(self):
+ if len(self.collection )== 0:
+ raise IndexError
+ return self.collection.pop[0]
+
+ def top_card(self):
+ return self.collection[len(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)
+
+
+
+
+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 = {'Spades' : Spades, 'Diamonds' : Diamonds, 'Hearts' : Hearts, 'Clubs' : Clubs}