Снежана обнови решението на 26.03.2014 02:56 (преди над 10 години)
+from collections import OrderedDict
+
+class Rank():
+ def __init__(self, symbol, view):
+ self.symbol = symbol
+ self.view = view
+ def __eq__(self, other):
+ return self.class_method() == other.class_method()
+
+ @classmethod
+ def class_method(cls):
+ return cls
+
+ def __repr__(self):
+ return str(self.view)
+
+class Suit():
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.class_method() == other.class_method()
+
+ @classmethod
+ def class_method(cls):
+ return cls
+
+class Two(Rank):
+ def __init__(self):
+ super(Two, self).__init__('2', "Two")
+
+class Three(Rank):
+ def __init__(self):
+ super(Three, self).__init__('3', "Three")
+
+class Four(Rank):
+ def __init__(self):
+ super(Four, self).__init__('4', "Four")
+
+class Five(Rank):
+ def __init__(self):
+ super(Five, self).__init__('5', "Five")
+
+class Six(Rank):
+ def __init__(self):
+ super(Six, self).__init__('6', "Six")
+
+class Seven(Rank):
+ def __init__(self):
+ super(Seven, self).__init__('7', "Seven")
+
+class Eight(Rank):
+ def __init__(self):
+ super(Eight, self).__init__('8', "Eight")
+
+class Nine(Rank):
+ def __init__(self):
+ super(Nine, self).__init__('9', "Nine")
+
+class Ten(Rank):
+ def __init__(self):
+ super(Ten, self).__init__('10', "Ten")
+
+class Jack(Rank):
+ def __init__(self):
+ super(Jack, self).__init__('J', "Jack")
+
+class Queen(Rank):
+ def __init__(self):
+ super(Queen, self).__init__('Q', "Queen")
+
+class King(Rank):
+ def __init__(self):
+ super(King, self).__init__('K', "King")
+
+class Ace(Rank):
+ def __init__(self):
+ super(Ace, self).__init__('A', "Ace")
+
+class Hearts(Suit):
+ def __init__(self):
+ super(Hearts, self).__init__('red')
+
+class Clubs(Suit):
+ def __init__(self):
+ super(Clubs, self).__init__('black')
+
+class Spades(Suit):
+ def __init__(self):
+ super(Spades, self).__init__('black')
+
+class Diamonds(Suit):
+ def __init__(self):
+ super(Diamonds, self).__init__('red')
+
+RANKS = OrderedDict([("Ace", Ace), ("Two", Two), ("Three", Three), ("Four", Four),
+ ("Five", Five), ("Six", Six), ("Seven", Seven), ("Eight", Eight),
+ ("Nine", Nine), ("Ten", Ten), ("Jack", Jack), ("Queen", Queen), ("King", King)])
+
+SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
+ ('Spades', Spades), ('Clubs', Clubs),])
+
+class Card():
+ def __init__(self, rank, suit):
+ self.__rank = rank.__call__()
+ self.__suit = suit.__call__()
+
+ @property
+ def rank(self):
+ return self.__rank
+
+ @property
+ def suit(self):
+ return self.__suit
+
+ @staticmethod
+ def find(dictionary, searched_value):
+ for key, value in dictionary.items():
+ if searched_value == value:
+ return key
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
+
+ def __repr__(self):
+ return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
+
+class CardCollection():
+ def __init__(self, collection = []):
+ self.collection = collection
+
+ def __len__(self):
+ return len(list(self.collection))
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ card = self.collection[index]
+ del self.collection[index]
+ return card
+
+ def draw_from_top(self):
+ card = self.collection[-1]
+ del self.collection[-1]
+ return card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+
+def StandardDeck():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+def BeloteDeck():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank not in ["Two", "Three", "Four", "Five", "Six"]:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+def SixtySix():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck