Пламен обнови решението на 24.03.2014 00:46 (преди над 10 години)
+class Rank():
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, ight):
+ return self.symbol == right.symbol
+
+ def __str__(self):
+ return type(self).__name__
+
+RANKS = {}
+TYPES_OF_RANK = []
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, "K")
+
+RANKS["King"] = type(King())
+TYPES_OF_RANK.append(RANKS["King"])
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, "Q")
+
+RANKS["Queen"] = type(Queen())
+TYPES_OF_RANK.append(RANKS["Queen"])
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, "J")
+
+RANKS["Jack"] = type(Jack())
+TYPES_OF_RANK.append(RANKS["Jack"])
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, "10")
+
+RANKS["Ten"] = type(Ten())
+TYPES_OF_RANK.append(RANKS["Ten"])
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, "9")
+
+RANKS["Nine"] = type(Nine())
+TYPES_OF_RANK.append(RANKS["Nine"])
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, "8")
+
+RANKS["Eight"] = type(Eight())
+TYPES_OF_RANK.append(RANKS["Eight"])
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, "7")
+
+RANKS["Seven"] = type(Seven())
+TYPES_OF_RANK.append(RANKS["Seven"])
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, "6")
+
+RANKS["Six"] = type(Six())
+TYPES_OF_RANK.append(RANKS["Six"])
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, "5")
+
+RANKS["Five"] = type(Five())
+TYPES_OF_RANK.append(RANKS["Five"])
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, "4")
+
+RANKS["Four"] = type(Four())
+TYPES_OF_RANK.append(RANKS["Four"])
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, "3")
+
+RANKS["Three"] = type(Three())
+TYPES_OF_RANK.append(RANKS["Three"])
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, "2")
+
+RANKS["Two"] = type(Two())
+TYPES_OF_RANK.append(RANKS["Two"])
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, "A")
+
+RANKS["Ace"] = type(Ace())
+TYPES_OF_RANK.append(RANKS["Ace"])
+
+SUITS = {}
+TYPES_OF_SUITS = []
+
+
+class Suit():
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, right):
+ return type(self) == type(right)
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, "red")
+
+
+SUITS["Diamonds"] = type(Diamonds())
+TYPES_OF_SUITS.append(SUITS["Diamonds"])
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, "black")
+
+SUITS["Clubs"] = type(Clubs())
+TYPES_OF_SUITS.append(SUITS["Clubs"])
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, "red")
+
+SUITS["Hearts"] = type(Hearts())
+TYPES_OF_SUITS.append(SUITS["Hearts"])
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, "black")
+
+
+SUITS["Spades"] = type(Spades())
+TYPES_OF_SUITS.append(SUITS["Spades"])
+
+
+class Card():
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(self, "suit", suit())
+
+ def __setattr__(self, *args):
+ raise Exception("can't set atribute")
+
+ def __eq__(self, right):
+ return self.suit == right.suit and self.rank == right.rank
+
+ def __str__(self):
+ return '{0} of {1}'.format(self.rank, self.suit)
+
+
+class CardCollection():
+ def __init__(self, collection=[]):
+ self.collection = [card for card in collection]
+
+ def draw(self, index):
+ card = Card(self.collection[index].rank, self.collection[index].suit)
+ del self.collection[index]
+ return card
+
+ def draw_from_top(self):
+ card = Card(self.collection[-1].rank.__class__,
+ self.collection[-1].suit.__class__)
+ del self.collection[-1]
+ return card
+
+ def draw_from_bottom(self):
+ card = Card(self.collection[0].rank, self.collection[0].suit)
+ del self.collection[0]
+ return card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandardDeck():
+ card_collection = []
+ for suit in TYPES_OF_SUITS:
+ for rank in TYPES_OF_RANK:
+ card_collection.append(Card(rank, suit))
+ return card_collection
+
+
+def BeloteDeck():
+ card_collection = []
+ for suit in TYPES_OF_SUITS:
+ for rank in TYPES_OF_RANK:
+ if rank == RANKS["Six"]:
+ break
+ card_collection.append(Card(rank, suit))
+ return card_collection
+
+
+def SixtySixDeck():
+ card_collection = []
+ for suit in TYPES_OF_SUITS:
+ for rank in TYPES_OF_RANK:
+ if rank == RANKS["Eight"]:
+ break
+ card_collection.append(Card(rank, suit))
+ return card_collection