Гергана обнови решението на 26.03.2014 16:47 (преди над 10 години)
+RANK_SYMBOLS = {'K': 'King', '6': 'Six', 'J': 'Jack', '5': 'Five',
+ 'Q': 'Queen', '10': 'Ten', 'A': 'Ace', '3': 'Three',
+ '8': 'Eight', '4': 'Four',
+ '2': 'Two', '7': 'Seven', '9': 'Nine'}
+SUITS_SYMBOLS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+RANKS_SYMBOLS_2 = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __str__(self):
+ out = str(RANK_SYMBOLS[self.symbol])
+ return out
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __str__(self):
+ return str(self.color)
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+def make_cls(name, args):
+ def my_init(self):
+ Rank.__init__(self, args)
+ return type(name, (Rank,), {'__init__': my_init})
+
+
+def make_cls_2(name):
+ def my_init(self):
+ Suit.__init__(self, name)
+ return type(name, (Suit,), {'__init__': my_init})
+
+RANKS = {RANK_SYMBOLS[sym]: make_cls(RANK_SYMBOLS[sym], sym)
+ for sym in RANK_SYMBOLS.keys()}
+
+SUITS = {suits: make_cls_2(suits) for suits in SUITS_SYMBOLS}
+
+
+class Card():
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+ def __delattr__(self, *args):
+ raise AttributeError("can't delete attribute")
+
+ def __init__(self, rank, suit):
+ super(Card, self).__setattr__('rank', rank())
+ super(Card, self).__setattr__('suit', suit())
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ agr = str(self.suit)
+ return str(self.rank) + " of " + agr.replace("\'", "")
+
+
+class CardCollection():
+ def __init__(self, collection=[]):
+ self.collection = collection
+ self.collection_index = 0
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __getitem__(self, key):
+ return self.collection[key]
+
+ def draw(self, index):
+ c = self.__getitem__(self.index)
+ self.collection.remove(c)
+ return c
+
+ def draw_from_top(self):
+ c = self.__getitem__(len(self.collection)-1)
+ self.collection.remove(c)
+ return c
+
+ def draw_from_bottom(self):
+ c = self.__getitem__(0)
+ self.collection.remove(c)
+ return c
+
+ def top_card(self):
+ return self.__getitem__(len(self.collection)-1)
+
+ def bottom_card(self):
+ return self.__getitem__(0)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ if self.collection_index < len(self.collection):
+ c = self.collection[self.collection_index]
+ self.collection_index += 1
+ return c
+ else:
+ self.collection_index = 0
+ raise StopIteration
+
+ def __str__(self):
+ res = []
+ for car in self.collection:
+ res.append(str(car))
+ #return '\n'.join(res)
+ return str(res)
+
+ def index(self, card):
+ #if card in self.collection:
+ return self.collection.index(card)
+ #else:
+ # raise ValueError
+
+
+def StandardDeck():
+ pass
+
+
+def BelotteDeck():
+ pass
+
+
+def SixtySixDeck():
+ pass