Георги обнови решението на 26.03.2014 01:26 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol):
+ if symbol == "A" or symbol == "J" or symbol == "Q" or symbol == "K"\
+ or (isinstance(symbol, int) and symbol > 0 and symbol < 11):
+ self.symbol = symbol
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+class Suit:
+ def __init__(self, suit):
+ if suit == "Hearts" or "Diamonds":
+ color = "red"
+ elif suit == "Spades" or "Clubs":
+ color = "black"
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = "A"
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = 2
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = 3
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = 4
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = 5
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = 6
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = 7
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = 8
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = 9
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = 10
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = "J"
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = "Q"
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = "K"
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = "red"
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = "black"
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = "black"
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = "red"
+
+
+RANKS = {
+ "Ace": Ace,
+ "Two": Two,
+ "Three": Three,
+ "Four": Four,
+ "Five": Five,
+ "Six": Six,
+ "Seven": Seven,
+ "Eight": Eight,
+ "Nine": Nine,
+ "Ten": Ten,
+ "Jack": Jack,
+ "Queen": Queen,
+ "King": King,
+}
+SUITS = {
+ "Hearts": Hearts,
+ "Spades": Spades,
+ "Clubs": Clubs,
+ "Diamonds": Diamonds,
+}
+
+class Card:
+ def __init__(self, rank, suit):
+ if rank in RANKS.values() and suit in SUITS.values():
+ self.rank = rank
+ self.suit = suit
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+ def __str__(self):
+ return self.rank().__class__.__name__ + " of " + self.suit().__class__.__name__
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.cards = []
+ for card in collection:
+ self.cards.append(card)
+ def __getitem__(self, i):
+ return self.cards[i]
+ def add(self, card):
+ self.cards.append(card)
+ def draw(self, i):
+ card = self.cards[i]
+ del self.cards[i]
+ return card
+ def draw_from_top(self):
+ return self.draw(0)
+ def draw_from_bottom(self):
+ return self.draw(len(self.cards) - 1)
+ def top_card(self):
+ return self.cards[0]
+ def top_bottom(self):
+ return self.cards[len(self.cards) - 1]
+ def index(self, card):
+ return self.cards.index(card)
+ def __len__(self):
+ return len(self.cards)
Не съм сигурен, че разбрах правилно условието.
test_card_instance коректен ли е?