Дамян обнови решението на 26.03.2014 16:26 (преди над 10 години)
+class Rank:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+
+class Suit:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+class Clubs(Suit):
+ colour = 'black'
+
+class Diamonds(Suit):
+ colour = 'red'
+
+class Hearts(Suit):
+ colour = 'red'
+
+class Spades(Suit):
+ colour = 'red'
+
+class Two(Rank):
+ symbol = '2'
+
+class Three(Rank):
+ symbol = '3'
+
+class Four(Rank):
+ symbol = '4'
+
+class Five(Rank):
+ symbol = '5'
+
+class Six(Rank):
+ symbol = '6'
+
+class Seven(Rank):
+ symbol = '7'
+
+class Eight(Rank):
+ symbol = '8'
+
+class Nine(Rank):
+ symbol = '9'
+
+class Ten(Rank):
+ symbol = 'Ten'
+
+class Jack(Rank):
+ symbol = 'J'
+
+class Queen(Rank):
+ symbol = 'Q'
+
+class King(Rank):
+ symbol = 'K'
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Card():
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ def __str__(self):
+ x, y = self._rank.__class__.__name__, self._suit.__class__.__name__
+ return str("{} of {}".format(x, y))
+
+ def __eq__(self, other):
+ return (self._rank, self._suit) == (other.rank, other.suit)
+
+ def __repr__(self):
+ return '<Card ' + self._rank.__class__.__name__ + ' of ' \
+ + self._suit.__class__.__name__ + '>'
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+RANK_TEMPORARY = (King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five,
+ Four, Three, Two, Ace)
+
+SUIT_TEMPORARY = (Diamonds, Clubs, Hearts, Spades)
+
+class CardCollection():
+ def __init__(self, collection = []):
+ self.collection = collection
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(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(car))
+
+def StandardDeck():
+ return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
+ for x in RANK_TEMPORARY]
+
+def BeloteDeck():
+ return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
+ for x in RANK_TEMPORARY[:7]]
+
+def SixtySixDeck():
+ return [crd(y, x) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:5]]
+
+SUITS = {}
+RANKS = {}
+
+
+for i in Suit.__subclasses__():
+ SUITS[i.__name__] = i
+
+
+for i in Rank.__subclasses__():
+ RANKS[i.__name__] = i