Елена обнови решението на 26.03.2014 16:13 (преди над 10 години)
+SORTED_RANKS = ["King", "Queen", "Jack", "Ten", "Nine", "Eight",
+ "Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
+
+SORTED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
+
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.rank
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.suit
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, "A")
+
+ def __str__(self):
+ return "Ace"
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, "2")
+
+ def __str__(self):
+ return "Two"
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, "3")
+
+ def __str__(self):
+ return "Three"
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, "4")
+
+ def __str__(self):
+ return "Four"
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, "5")
+
+ def __str__(self):
+ return "Five"
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, "6")
+
+ def __str__(self):
+ return "Six"
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, "7")
+
+ def __str__(self):
+ return "Seven"
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, "8")
+
+ def __str__(self):
+ return "Eight"
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, "9")
+
+ def __str__(self):
+ return "Nine"
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, "10")
+
+ def __str__(self):
+ return "Ten"
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, "J")
+
+ def __str__(self):
+ return "Jack"
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, "Q")
+
+ def __str__(self):
+ return "Queen"
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, "K")
+
+ def __str__(self):
+ return "King"
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, "red")
+
+ def __str__(self):
+ return "Hearts"
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, "black")
+
+ def __str__(self):
+ return "Clubs"
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, "red")
+
+ def __str__(self):
+ return "Diamonds"
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, "black")
+
+ def __str__(self):
+ return "Spades"
+
+RANKS = {
+ "Ace": Ace().__class__,
+ "Two": Two().__class__,
+ "Three": Three().__class__,
+ "Four": Four().__class__,
+ "Five": Five().__class__,
+ "Six": Six().__class__,
+ "Seven": Seven().__class__,
+ "Eight": Eight().__class__,
+ "Nine": Nine().__class__,
+ "Ten": Ten().__class__,
+ "Jack": Jack().__class__,
+ "Queen": Queen().__class__,
+ "King": King().__class__
+}
+
+SUITS = {
+ "Hearts": Hearts().__class__,
+ "Clubs": Clubs().__class__,
+ "Spades": Spades().__class__,
+ "Diamonds": Diamonds().__class__
+}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(self, "suit", suit())
+
+ def __str__(self):
+ return "%s of %s" % (self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection(Card):
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def draw(self, i):
+ return self.collection.pop(i)
+
+ 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(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandartDeck():
+ deck = []
+ for suit in SORTED_SUITS:
+ for rank in SORTED_RANKS:
+ deck.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return deck
+
+
+def BeloteDeck():
+ result = []
+ for suit in SORTED_SUITS:
+ for rank in SORTED_RANKS:
+ if rank != "Two" and rank != "Three" and rank != "Four" \
+ and rank != "Five"and rank != "Six":
+ result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return result
+
+
+def SixtySixDeck():
+ result = []
+ for suit in SORTED_SUITS:
+ for rank in SORTED_RANKS:
+ if rank != "Two" and rank != "Three" and rank != "Four" \
+ and rank != "Five"and rank != "Six" \
+ and rank != "Seven" and rank != "Eight":
+ result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return result