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