Радослав обнови решението на 26.03.2014 16:55 (преди над 10 години)
+class Rank:
+ def __init__(self, name, symbol):
+ self.name = name
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.name == other.name and self.symbol == other.symbol
+
+ def __call__(self):
+ return self
+
+ def __str__(self):
+ return self.name
+
+
+class Suit:
+ def __init__(self, name, color):
+ self.name = name
+ self.color = color
+
+ def __eq__(self, other):
+ return self.name == other.name and self.color == other.color
+
+ def __call__(self):
+ return self
+
+ def __str__(self):
+ return self.name
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'King', 'K')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Queen', 'Q')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Jack', 'J')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ten', '10')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Nine', '9')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Eight', '8')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Seven', '7')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Six', '6')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Five', '5')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Four', '4')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Three', '3')
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Two', '2')
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ace', 'A')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds', 'red')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Hearts', 'red')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Spades', 'black')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Clubs', 'black')
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __call__(self):
+ return self
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+ def __delattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+
+class CardCollection:
+ def __init__(self, collection = []):
+ self.collection = collection
+
+ def __getitem__(self, card):
+ return self.collection[card]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ 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[-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 __str__(self):
+ return str([str(card) for card in self.collection])
+
+
+RANKS = dict()
+RANKS['King'] = King
+RANKS['Queen'] = Queen
+RANKS['Jack'] = Jack
+RANKS['Ten'] = Ten
+RANKS['Nine'] = Nine
+RANKS['Eight'] = Eight
+RANKS['Seven'] = Seven
+RANKS['Six'] = Six
+RANKS['Five'] = Five
+RANKS['Four'] = Four
+RANKS['Three'] = Three
+RANKS['Two'] = Two
+RANKS['Ace'] = Ace
+
+
+SUITS = dict()
+SUITS['Diamonds'] = Diamonds
+SUITS['Hearts'] = Hearts
+SUITS['Spades'] = Spades
+SUITS['Clubs'] = Clubs
+
+
+def StandardDeck():
+ ordered_ranks = (RANKS['King'], RANKS['Queen'], RANKS['Jack'], RANKS['Ten'], RANKS['Nine'], RANKS['Eight'], RANKS['Seven'], RANKS['Six'],
+ RANKS['Five'], RANKS['Four'], RANKS['Three'], RANKS['Two'], RANKS['Ace'])
+ ordered_suits = (SUITS['Diamonds'], SUITS['Hearts'], SUITS['Spades'], SUITS['Clubs'])
+ deck = CardCollection(list())
+
+ for suit in ordered_suits:
+ for rank in ordered_ranks:
+ deck.add(Card(rank, suit))
+
+ return deck
+
+
+def BeloteDeck():
+ ordered_ranks = (RANKS['Ace'], RANKS['King'], RANKS['Queen'], RANKS['Jack'], RANKS['Ten'], RANKS['Nine'], RANKS['Eight'], RANKS['Seven'])
+ ordered_suits = (SUITS['Diamonds'], SUITS['Hearts'], SUITS['Spades'], SUITS['Clubs'])
+ deck = CardCollection(list())
+
+ for suit in ordered_suits:
+ for rank in ordered_ranks:
+ deck.add(Card(rank, suit))
+
+ return deck
+
+def SixtySixDeck():
+ ordered_ranks = (RANKS['Ace'], RANKS['King'], RANKS['Queen'], RANKS['Jack'], RANKS['Ten'], RANKS['Nine'])
+ ordered_suits = (SUITS['Diamonds'], SUITS['Hearts'], SUITS['Spades'], SUITS['Clubs'])
+ deck = CardCollection(list())
+
+ for suit in ordered_suits:
+ for rank in ordered_ranks:
+ deck.add(Card(rank, suit))
+
+ return deck