Петьо обнови решението на 26.03.2014 16:40 (преди почти 11 години)
+import itertools
+
+
+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)
+
+
+# the 13 card ranks
+class Two(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Two')
+
+
+class Three(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Three')
+
+
+class Four(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Four')
+
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Five')
+
+
+class Six(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Six')
+
+
+class Seven(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Seven')
+
+
+class Eight(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Eight')
+
+
+class Nine(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Nine')
+
+
+class Ten(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ten')
+
+
+class Jack(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Jack')
+
+
+class Queen(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Queen')
+
+
+class King(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'King')
+
+
+class Ace(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ace')
+
+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}
+
+
+# The four card suits
+
+class Suit:
+
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return str(self.color)
+
+
+class Diamonds(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds')
+
+
+class Hearts(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Hearts')
+
+
+class Spades(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Spades')
+
+
+class Clubs(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Clubs')
+
+SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
+ 'Spades': Spades, 'Clubs': Clubs}
+
+
+class Card():
+
+ def __init__(self, Rank, Suit):
+ object.__setattr__(self, 'rank', Rank())
+ object.__setattr__(self, 'suit', Suit())
+
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+ def __delattr__(self, *args):
+ raise AttributeError("can't delete attribute")
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return '{} of {}'.format(self.rank, self.suit)
+
+
+class CardCollection():
+
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ # check for duplicate cards?
+ def add(self, new_card):
+ self.collection.append(new_card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(-1)
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandartDeck():
+ ordered_ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+ ordered_suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+ standart_deck = []
+
+ for card in itertools.product(ordered_suits, ordered_ranks):
+ standart_deck.append('{} of {}'.format(card[1], card[0]))
+ return standart_deck
+
+
+def BeloteDeck():
+ ordered_ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Ace']
+ ordered_suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+ belote_deck = []
+ for card in itertools.product(ordered_suits, ordered_ranks):
+ belote_deck.append('{} of {}'.format(card[1], card[0]))
+ return belote_deck
+
+
+def SixtySixDeck():
+ ordered_ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+ ordered_suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+ sixty_six_deck = []
+ for card in itertools.product(ordered_suits, ordered_ranks):
+ sixty_six_deck.append('{} of {}'.format(card[1], card[0]))
+ return sixty_six_deck