Виктор обнови решението на 22.03.2014 20:54 (преди над 10 години)
+class Rank:
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.name
+
+
+class Suit:
+ def __eq__(self, other):
+ return self.name == other.name
+
+ def __str__(self):
+ return self.name
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = 'A'
+ self.name = 'Ace'
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = '2'
+ self.name = 'Two'
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = '3'
+ self.name = 'Three'
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = '4'
+ self.name = 'Four'
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = '5'
+ self.name = 'Five'
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = '6'
+ self.name = 'Six'
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = '7'
+ self.name = 'Seven'
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = '8'
+ self.name = 'Eight'
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = '9'
+ self.name = 'Nine'
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = '10'
+ self.name = 'Ten'
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = 'J'
+ self.name = 'Jack'
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = 'Q'
+ self.name = 'Queen'
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = 'K'
+ self.name = 'King'
+
+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}
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = 'black'
+ self.name = 'Clubs'
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = 'red'
+ self.name = 'Diamonds'
+
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = 'red'
+ self.name = 'Hearts'
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = 'black'
+ self.name = 'Spades'
+
+SUITS = {'Clubs': Clubs, 'Diamonds': Diamonds,
+ 'Hearts': Hearts, 'Spades': Spades}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank
+ self.suit = suit
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank()) + ' of ' + str(self.suit())
+
+ def __repr__(self):
+ return '<Card ' + str(self.rank()) + ' of ' + str(self.suit()) + '>'
+
+ def __setattr__(self, name, value):
+ if hasattr(self, name):
+ raise AttributeError('can\'t set attribute')
+ else:
+ self.__dict__[name] = value
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = collection
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __repr__(self):
+ return repr(self.collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(-1)
+
+ 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)
+
+suits_ordered = [Diamonds, Clubs, Hearts, Spades]
+ranks_standard_ordered = [King, Queen, Jack, Ten, Nine, Eight, Seven,
+ Six, Five, Four, Three, Two, Ace]
+ranks_belote_ordered = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
+ranks_sixty_six_ordered = [King, Queen, Jack, Ten, Nine, Ace]
+
+
+def StandardDeck():
+ result = CardCollection([])
+ for suit in suits_ordered:
+ for rank in ranks_standard_ordered:
+ result.add(Card(rank, suit))
+ return result
+
+
+def BeloteDeck():
+ result = CardCollection([])
+ for suit in suits_ordered:
+ for rank in ranks_belote_ordered:
+ result.add(Card(rank, suit))
+ return result
+
+
+def SixtySixDeck():
+ result = CardCollection([])
+ for suit in suits_ordered:
+ for rank in ranks_sixty_six_ordered:
+ result.add(Card(rank, suit))
+ return result