Константин обнови решението на 26.03.2014 12:14 (преди над 10 години)
+class Rank:
+
+ def __init__(self, symbol_):
+ self.symbol = symbol_
+
+
+class Suit:
+
+ def __init__(self, color_):
+ self.color = color_
+
+
+class Two(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __str__(self):
+ return 'Two'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Three(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __str__(self):
+ return 'Three'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Four(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __str__(self):
+ return 'Four'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __str__(self):
+ return 'Five'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Six(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __str__(self):
+ return 'Six'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Seven(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __str__(self):
+ return 'Seven'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Eight(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __str__(self):
+ return 'Eight'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Nine(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __str__(self):
+ return 'Nine'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ten(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __str__(self):
+ return 'Ten'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Jack(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+ def __str__(self):
+ return 'Jack'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Queen(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+ def __str__(self):
+ return 'Queen'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class King(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+ def __str__(self):
+ return 'King'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ace(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+ def __str__(self):
+ return 'Ace'
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Spades(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return 'Spades'
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+
+class Diamonds(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return 'Diamonds'
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+
+class Clubs(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return 'Clubs'
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+
+class Hearts(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return 'Hearts'
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+from collections import OrderedDict
+
+RANKS = OrderedDict([('King', type(King())), ('Queen', type(Queen())),
+ ('Jack', type(Jack())), (
+ 'Ten', type(Ten())), ('Nine', type(Nine())),
+ ('Eight', type(Eight())), ('Seven', type(Seven())), ('Six', type(Six())),
+ ('Five', type(Five())), ('Four', type(Four())), ('Three', type(Three())),
+ ('Two', type(Two())), ('Ace', type(Ace()))])
+
+SUITS = OrderedDict([('Hearts', type(Hearts())), ('Spades', type(Spades())),
+ ('Clubs', type(Clubs())), ('Diamonds', type(Diamonds()))])
+
+
+class Card():
+
+ def __init__(self, rank_, suit_):
+ object.__setattr__(self, 'rank', rank_())
+ object.__setattr__(self, 'suit', suit_())
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __setattr__(self, name, value):
+ raise AttributeError(": can't set attribute")
+
+
+class CardCollection:
+
+ def __init__(self, collection=list()):
+ self.deck = list(collection)
+
+ def __len__(self):
+ return len(self.deck)
+
+ def __getitem__(self, i):
+ return (self.deck)[i]
+
+ def add(self, card):
+ return self.deck.append(card)
+
+ def draw(self, index):
+ return self.deck.pop(index)
+
+ def draw_from_top(self):
+ return self.deck.pop()
+
+ def draw_from_bottom(self):
+ return self.deck.pop(0)
+
+ def top_card(self):
+ return self.deck[len(self.deck) - 1]
+
+ def bottom_card(sefl):
+ return self.deck[0]
+
+ def index(self, card):
+ return self.deck.index(card)
+
+
+def all_cards():
+ cards = list()
+ for suit in SUITS:
+ for rank in RANKS:
+ cards.append(Card(RANKS[str(rank)], SUITS[str(suit)]))
+ return cards
+
+
+def StandratDeck():
+ deck = CardCollection(all_cards())
+ return deck
+
+
+def BeloteDeck():
+ deck = list()
+ no_need_ranks = [Two(), Three(), Four(), Five(), Six()]
+ cards = all_cards()
+ for card in cards:
+ if card.rank not in no_need_ranks:
+ deck.append(card)
+ return CardCollection(deck)
+
+
+def SixtySixDeck():
+ deck = list()
+ no_need_ranks = [Two(), Three(), Four(), Five(), Six(), Seven(), Eight()]
+ cards = all_cards()
+ for card in cards:
+ if card.rank not in no_need_ranks:
+ deck.append(card)
+ return CardCollection(deck)