Денис обнови решението на 25.03.2014 18:42 (преди над 10 години)
+class Rank:
+ symbol=[]
+ def __init__(self, symbol):
+ self.symbol=symbol
+
+ def __eq__(self, other):
+ return self.symbol==other.symbol
+
+ def __str__(self):
+ return type(self).__name__
+
+class Suit:
+ def __init__(self, color):
+ self.color=color
+
+ def __eq__(self, other):
+ return self.color==other.color
+
+ def __str__(self):
+ return type(self).__name__
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self,'A')
+
+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 Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Clubs')
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Hearts')
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Diamonds')
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Spades')
+
+t=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(), Eight(), Nine(),
+ Ten(), Jack(), Queen(), King()]
+
+s=[Hearts(), Spades(), Diamonds(), Clubs()]
+
+RANKS={type(x).__name__:type(x) for x in t}
+SUITS={x.color:type(x) for x in s}
+
+class Card:
+ rank, suit= [], []
+
+ 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)
+
+class CardCollection:
+
+ def __init__(self, colection=[]):
+ self.index=0
+ self.colection=[]
+ for x in colection:
+ self.colection.append(x)
+ self.index+=1
+
+ def add(self, card):
+ self.colection.append(card)
+ self.index += 1
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ if self.index == 0:
+ raise StopIteration
+ self.index=len(self.colection)
+ self.index -= 1
+ return self.colection[self.index]
+
+ def __getitem__(self, i):
+ return (self.colection)[i]
+
+ def draw(self, index):
+ self.index -= 1
+ return (self.colection).pop(index)
+
+ def draw_from_top(self):
+ self.index -= 1
+ return (self.colection).pop()
+
+ def draw_from_bottom(self):
+ self.index -= 1
+ return (self.colection).pop(0)
+
+ def top_card(self):
+ return (self.colection)[len(self)-1]
+
+ def bottom_card(self):
+ return (self.colection)[0]
+
+ def index(self, card):
+ return (self.colection).index(card)
+
+ def __len__(self):
+ return len(self.colection)
+
+ def __eq__(self, other):
+ return self.colection == other.colection
+
+
+standart_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
+suits_for_deck=["Diamonds", "Clubs", "Hearts", "Spades"]
+belot_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Ace"]
+sixty_six_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
+
+def StandartDeck():
+ deck=CardCollection()
+ for x in suits_for_deck:
+ for y in standart_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck
+
+def BeloteDeck():
+ deck=CardCollection()
+ deck.draw_from_bottom()
+ for x in suits_for_deck:
+ for y in belot_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck
+
+def SixtySixDeck():
+ deck=CardCollection()
+ deck.draw_from_bottom()
+ for x in suits_for_deck:
+ for y in sixty_six_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck