Александър обнови решението на 26.03.2014 16:53 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self,other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return str(self.symbol)
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self)
+
+
+class Suit:
+ def __init__(self,color):
+ self.color = color
+
+ def __eq__(self,other):
+ return type(self).__name__ == type(other).__name__
+
+ def __str__(self):
+ return str(self.color)
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self)
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self)
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self)
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self)
+
+
+RANKS = {'Two':Two,'Three':Three,'Four':Four,'Five':Five,'Six':Six,
+ 'Seven':Seven,'Eight':Eight,'Nine':Nine,'Ten':Ten,'Jack':Jack,
+ 'Queen':Queen,'King':King,'Ace':Ace}
+
+
+SUITS = {'Hearts':Hearts,'Clubs':Clubs,'Diamonds':Diamonds,'Spades':Spades}
+
+
+class Card:
+ def __init__(self, rank,suit):
+ super(Card, self).__setattr__('rank', Rank())
+ super(Card, self).__setattr__('suit', Suit())
+ self.__dict__[Rank] = suit
+ self.__dict__[Rank]= rank
+
+ def __eq__(self,other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank) and str(self.suit)
+
+
+KEY_ORDERS=list(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace'])
+
+DECK = [Card(RANKS[R], SUITS[S]) for S in KEY_ORDERS for R in KEY_ORDERS]
+
+
+class CardCollection:
+ def __init__(self,collection):
+ self.collection = collection
+
+ def __len__(self):
+ return len(CardCollection)
+
+ def draw(self, index):
+ return selfcollection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(obj=len(collection))
+
+ def draw_from_bottom(self):
+ return collection.pop(obj=collection[0])
+
+ def top_card(self):
+ return self.collection[len(collection)]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self,card):
+ return self.collection.append(card)
+
+ def index(self,card):
+ return self.collection.index(card)