Решение на Тесте карти от Венцислав Велков

Обратно към всички решения

Към профила на Венцислав Велков

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

class Rank:
def __init__(self):
self.rank = self.__class__.__name__
if self.rank in {'Ace', 'King', 'Queen', 'Jack'}:
self.symbol = self.rank[0]
else:
self.symbol = str(abs(ALL_RANKS.index(self.rank) - 13))
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return self.rank
class Suit:
def __init__(self):
self.suit = self.__class__.__name__
if self.suit in {'Diamonds', 'Hearts'}:
self.color = 'red'
else:
self.color = 'black'
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
return self.suit
ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace']
ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
RANKS = {rank: type(rank, (Rank,), {}) for rank in ALL_RANKS}
SUITS = {suit: type(suit, (Suit,), {}) for suit in ALL_SUITS}
class Card:
def __init__(self, rank, suit):
self.__rank = rank
self.__suit = suit
def __str__(self):
return str(self.__rank()) + ' of ' + str(self.__suit())
def __repr__(self):
return '<Card ' + self.__str__() + '>'
def __eq__(self, other):
return self.__rank == other.__rank and self.__suit == other.__suit
@property
def rank(self):
return self.__rank()
@property
def suit(self):
return self.__suit()
class CardCollection:
def __init__(self, collection=[]):
self.cards = list(collection)
def __getitem__(self, index):
return self.cards[index]
def __setitem__(self, index, value):
self.cards[i] = value
def __len__(self):
return len(self.cards)
def __iter__(self):
for card in self.cards:
yield card
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[len(self.cards) - 1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
def StandardDeck():
return CardCollection([Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS])
def BeloteDeck():
return CardCollection([Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:7] + ['Ace']])
def SixtySixDeck():
return CardCollection([Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:5] + ['Ace']])

Лог от изпълнението

................
----------------------------------------------------------------------
Ran 16 tests in 0.018s

OK

История (5 версии и 1 коментар)

Венцислав обнови решението на 22.03.2014 03:00 (преди над 10 години)

+class Rank:
+ def __init__(self, rank=''):
+ self.rank = rank
+
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ def __init__(self, suit=''):
+ self.suit = suit
+
+ def __eq__(self, other):
+ return self.suit == other.suit
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+RANKS = {}
+SUITS = {}
+ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
+ 'Eight', 'Seven', 'Six', 'Five', 'Four',
+ 'Three', 'Two', 'Ace']
+ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+for r in ALL_RANKS:
+ RANKS[r] = type(r, (Rank,), {})
+
+
+for s in ALL_SUITS:
+ SUITS[s] = type(s, (Suit,), {})
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.__rank = rank
+ self.__suit = suit
+
+ def __str__(self):
+ return str(self.__rank()) + ' of ' + str(self.__suit())
+
+ def __repr__(self):
+ return '<Card ' + self.__str__() + '>'
+
+ def __eq__(self, other):
+ return self.__rank == other.__rank and self.__suit == other.__suit
+
+ @property
+ def rank(self):
+ return self.__rank()
+
+ @property
+ def suit(self):
+ return self.__suit()
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.cards = list(collection)
+
+ def __getitem__(self, index):
+ return self.cards[index]
+
+ def __len__(self):
+ return len(self.cards)
+
+ def draw(self, index):
+ return self.cards.pop(index)
+
+ def draw_from_top(self):
+ return self.cards.pop()
+
+ def draw_from_bottom(self):
+ return self.cards.pop(0)
+
+ def top_card(self):
+ return self.cards[len(self.cards) - 1]
+
+ def bottom_card(self):
+ return self.cards[0]
+
+ def add(self, card):
+ self.cards.append(card)
+
+ def index(self, card):
+ return self.cards.index(card)
+
+
+def StandardDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS]
+
+
+def BeloteDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:7] + ['Ace']]
+
+
+def SixtySixDeck():
+ return [Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:5] + ['Ace']]

Венцислав обнови решението на 22.03.2014 03:02 (преди над 10 години)

class Rank:
def __init__(self, rank=''):
self.rank = rank
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, suit=''):
self.suit = suit
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
return self.__class__.__name__
RANKS = {}
SUITS = {}
ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
- 'Eight', 'Seven', 'Six', 'Five', 'Four',
- 'Three', 'Two', 'Ace']
+ 'Eight', 'Seven', 'Six', 'Five', 'Four',
+ 'Three', 'Two', 'Ace']
ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
for r in ALL_RANKS:
RANKS[r] = type(r, (Rank,), {})
for s in ALL_SUITS:
SUITS[s] = type(s, (Suit,), {})
class Card:
def __init__(self, rank, suit):
self.__rank = rank
self.__suit = suit
def __str__(self):
return str(self.__rank()) + ' of ' + str(self.__suit())
def __repr__(self):
return '<Card ' + self.__str__() + '>'
def __eq__(self, other):
return self.__rank == other.__rank and self.__suit == other.__suit
@property
def rank(self):
return self.__rank()
@property
def suit(self):
return self.__suit()
class CardCollection:
def __init__(self, collection=[]):
self.cards = list(collection)
def __getitem__(self, index):
return self.cards[index]
def __len__(self):
return len(self.cards)
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[len(self.cards) - 1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
def StandardDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS]
def BeloteDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:7] + ['Ace']]
def SixtySixDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:5] + ['Ace']]

Венцислав обнови решението на 22.03.2014 11:22 (преди над 10 години)

class Rank:
def __init__(self, rank=''):
self.rank = rank
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, suit=''):
self.suit = suit
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
return self.__class__.__name__
-RANKS = {}
-SUITS = {}
ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace']
ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
-for r in ALL_RANKS:
- RANKS[r] = type(r, (Rank,), {})
-
-
-for s in ALL_SUITS:
- SUITS[s] = type(s, (Suit,), {})
+RANKS = {rank: type(rank, (Rank,), {}) for rank in ALL_RANKS}
+SUITS = {suit: type(suit, (Suit,), {}) for suit in ALL_SUITS}
class Card:
def __init__(self, rank, suit):
self.__rank = rank
self.__suit = suit
def __str__(self):
return str(self.__rank()) + ' of ' + str(self.__suit())
def __repr__(self):
return '<Card ' + self.__str__() + '>'
def __eq__(self, other):
return self.__rank == other.__rank and self.__suit == other.__suit
@property
def rank(self):
return self.__rank()
@property
def suit(self):
return self.__suit()
class CardCollection:
def __init__(self, collection=[]):
self.cards = list(collection)
def __getitem__(self, index):
return self.cards[index]
def __len__(self):
return len(self.cards)
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[len(self.cards) - 1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
def StandardDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS]
def BeloteDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:7] + ['Ace']]
def SixtySixDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:5] + ['Ace']]

Венцислав обнови решението на 26.03.2014 02:52 (преди над 10 години)

class Rank:
- def __init__(self, rank=''):
- self.rank = rank
+ def __init__(self):
+ self.rank = self.__class__.__name__
+ if self.rank in {'Ace', 'King', 'Queen', 'Jack'}:
+ self.symbol = self.rank[0]
+ else:
+ self.symbol = str(abs(ALL_RANKS.index(self.rank) - 13))
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
- return self.__class__.__name__
+ return self.rank
class Suit:
- def __init__(self, suit=''):
- self.suit = suit
+ def __init__(self):
+ self.suit = self.__class__.__name__
+ if self.suit in {'Diamonds', 'Hearts'}:
+ self.color = 'red'
+ else:
+ self.color = 'black'
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
- return self.__class__.__name__
+ return self.suit
ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace']
ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
RANKS = {rank: type(rank, (Rank,), {}) for rank in ALL_RANKS}
SUITS = {suit: type(suit, (Suit,), {}) for suit in ALL_SUITS}
class Card:
def __init__(self, rank, suit):
self.__rank = rank
self.__suit = suit
def __str__(self):
return str(self.__rank()) + ' of ' + str(self.__suit())
def __repr__(self):
return '<Card ' + self.__str__() + '>'
def __eq__(self, other):
return self.__rank == other.__rank and self.__suit == other.__suit
@property
def rank(self):
return self.__rank()
@property
def suit(self):
return self.__suit()
class CardCollection:
def __init__(self, collection=[]):
self.cards = list(collection)
def __getitem__(self, index):
return self.cards[index]
+ def __setitem__(self, index, value):
+ self.cards[i] = value
+
def __len__(self):
return len(self.cards)
+
+ def __iter__(self):
+ for card in self.cards:
+ yield card
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[len(self.cards) - 1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
def StandardDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS]
def BeloteDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:7] + ['Ace']]
def SixtySixDeck():
return [Card(RANKS[r], SUITS[s])
for s in ALL_SUITS
for r in ALL_RANKS[:5] + ['Ace']]

Венцислав обнови решението на 26.03.2014 14:38 (преди над 10 години)

class Rank:
def __init__(self):
self.rank = self.__class__.__name__
if self.rank in {'Ace', 'King', 'Queen', 'Jack'}:
self.symbol = self.rank[0]
else:
self.symbol = str(abs(ALL_RANKS.index(self.rank) - 13))
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return self.rank
class Suit:
def __init__(self):
self.suit = self.__class__.__name__
if self.suit in {'Diamonds', 'Hearts'}:
self.color = 'red'
else:
self.color = 'black'
def __eq__(self, other):
return self.suit == other.suit
def __str__(self):
return self.suit
ALL_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace']
ALL_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
RANKS = {rank: type(rank, (Rank,), {}) for rank in ALL_RANKS}
SUITS = {suit: type(suit, (Suit,), {}) for suit in ALL_SUITS}
class Card:
def __init__(self, rank, suit):
self.__rank = rank
self.__suit = suit
def __str__(self):
return str(self.__rank()) + ' of ' + str(self.__suit())
def __repr__(self):
return '<Card ' + self.__str__() + '>'
def __eq__(self, other):
return self.__rank == other.__rank and self.__suit == other.__suit
@property
def rank(self):
return self.__rank()
@property
def suit(self):
return self.__suit()
class CardCollection:
def __init__(self, collection=[]):
self.cards = list(collection)
def __getitem__(self, index):
return self.cards[index]
def __setitem__(self, index, value):
self.cards[i] = value
def __len__(self):
return len(self.cards)
def __iter__(self):
for card in self.cards:
yield card
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[len(self.cards) - 1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
def StandardDeck():
- return [Card(RANKS[r], SUITS[s])
- for s in ALL_SUITS
- for r in ALL_RANKS]
+ return CardCollection([Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS])
def BeloteDeck():
- return [Card(RANKS[r], SUITS[s])
- for s in ALL_SUITS
- for r in ALL_RANKS[:7] + ['Ace']]
+ return CardCollection([Card(RANKS[r], SUITS[s])
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:7] + ['Ace']])
def SixtySixDeck():
- return [Card(RANKS[r], SUITS[s])
- for s in ALL_SUITS
+ return CardCollection([Card(RANKS[r], SUITS[s])
- for r in ALL_RANKS[:5] + ['Ace']]
+ for s in ALL_SUITS
+ for r in ALL_RANKS[:5] + ['Ace']])