Евгени обнови решението на 22.03.2014 22:08 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol=None):
+ self.symbol = symbol
+
+
+class Suit:
+ def __init__(self, color=None):
+ self.color = color
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Ace'
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Jack'
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'King'
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Six'
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Five'
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Queen'
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Ten'
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Three'
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Eight'
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Four'
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Two'
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Seven'
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Nine'
+
+
+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}
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Spades'
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Diamonds'
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Hearts'
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __str__(self):
+ return 'Clubs'
+
+
+SUITS = {'Spades': Spades, 'Diamonds': Diamonds,
+ 'Hearts': Hearts, 'Clubs': Clubs}
+
+
+class Card(object):
+ def __init__(self, rank, suit):
+ self._rank = rank
+ self._suit = suit
+
+ def __str__(self):
+ return "{} of {}".format(self._rank(), self._suit())
+
+ def __repr__(self):
+ return '<Card ' + str(self._rank()) + ' of ' + str(self._suit()) + '>'
+
+ def __eq__(self, other):
+ return self._rank == other._rank and self._suit == other._suit
+
+ @property
+ def rank(self):
+ return self._rank()
+
+ @property
+ def suit(self):
+ return self._suit()
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def draw(self, index):
+ card = self.collection[index]
+ self.collection = self.collection[:index] + self.collection[index + 1:]
+ return card
+
+ def draw_from_top(self):
+ card = self.collection[-1]
+ self.collection = self.collection[:-1]
+ return card
+
+ def draw_from_bottom(self):
+ card = self.collection[0]
+ self.collection = self.collection[1:]
+ return card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ for i in range(len(self.collection)):
+ if self.collection[i] == card:
+ return i
+ raise ValueError('%r is not in list' % (card))
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandardDeck():
+ deck = CardCollection()
+ for suit in ['Spades', 'Hearts', 'Diamonds', 'Clubs']:
+ for rank in ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven',
+ 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King']:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+
+def BeloteDeck():
+ deck = CardCollection()
+ for suit in ['Spades', 'Hearts', 'Diamonds', 'Clubs']:
+ for rank in ['Ace', 'Seven', 'Eight', 'Nine',
+ 'Ten', 'Jack', 'Queen', 'King']:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+
+def SixtySixDeck():
+ deck = CardCollection()
+ for suit in ['Spades', 'Hearts', 'Diamonds', 'Clubs']:
+ for rank in ['Ace', 'Nine', 'Ten', 'Jack', 'Queen', 'King']:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
+ return deck