Решение на Тесте карти от Цветелина Борисова

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

Към профила на Цветелина Борисова

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 14 успешни тест(а)
  • 2 неуспешни тест(а)

Код

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection:
def __init__(self, collection=[]):
self.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return iter(self.__collection)
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

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

...F.F..........
======================================================================
FAIL: test_deck_index (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-1holzuj/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
AssertionError: 0 != 2

======================================================================
FAIL: test_deck_order (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-1holzuj/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb77e948c> != <solution.Card object at 0xb77fd90c>

----------------------------------------------------------------------
Ran 16 tests in 0.082s

FAILED (failures=2)

История (12 версии и 2 коментара)

Цветелина обнови решението на 21.03.2014 00:55 (преди над 10 години)

+RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
+ '7', '6', '5', '4', '3', '2', 'A']
+
+
+ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+
+
+ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+class CardElement:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__ == self.__class__
+
+
+class Suit(CardElement):
+
+ def __init__(self):
+ if ORDERED_SUITS.index(self.__class__.__name__) % 2:
+ self.__color = 'red'
+ else:
+ self.__color = 'black'
+
+
+class Rank(CardElement):
+
+ def __init__(self):
+ index = ORDERED_RANKS.index(self.__class__.__name__)
+ self.__symbol = RANKS_SYMBOLS[index]
+
+
+class Two(Rank):
+ pass
+
+
+class Three(Rank):
+ pass
+
+
+class Four(Rank):
+ pass
+
+
+class Five(Rank):
+ pass
+
+
+class Six(Rank):
+ pass
+
+
+class Seven(Rank):
+ pass
+
+
+class Eight(Rank):
+ pass
+
+
+class Nine(Rank):
+ pass
+
+
+class Ten(Rank):
+ pass
+
+
+class Ace(Rank):
+ pass
+
+
+class King(Rank):
+ pass
+
+
+class Queen(Rank):
+ pass
+
+
+class Jack(Rank):
+ pass
+
+
+class Hearts(Suit):
+ pass
+
+
+class Clubs(Suit):
+ pass
+
+
+class Spades(Suit):
+ pass
+
+
+class Diamonds(Suit):
+ pass
+
+
+RANKS = {klass: eval(klass) for klass in ORDERED_RANKS}
+
+
+SUITS = {klass: eval(klass) for klass in ORDERED_SUITS}
+
+
+class Card:
+
+ def __init__(self, rank_class, suit_class):
+ self.__rank = rank_class()
+ self.__suit = suit_class()
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank, self.suit)
+
+ 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.__collection = 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)
+
+ def __str__(self):
+ return str([str(card) for card in self.__collection])
+
+ def __len__(self):
+ return len(self.__collection)
+
+ def __getitem__(self, index):
+ return self.__collection[index]
+
+ def __iter__(self):
+ return self.__collection.__iter__()
+
+
+def StandardDeck():
+ return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS
+ for rank in ORDERED_RANKS]
+
+
+def BelotDeck():
+ ranks = ORDERED_RANKS[0:7:]
+ ranks.append('Ace')
+ return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS[0:7:]
+ for rank in ranks]
+
+
+def SixtySixDeck():
+ ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+ return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS[0:7:]
+ for rank in ranks]

Цветелина обнови решението на 21.03.2014 14:16 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__ == self.__class__
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'red'
else:
self.__color = 'black'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
-class Two(Rank):
- pass
+RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
-class Three(Rank):
- pass
+SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
-class Four(Rank):
- pass
-
-
-class Five(Rank):
- pass
-
-
-class Six(Rank):
- pass
-
-
-class Seven(Rank):
- pass
-
-
-class Eight(Rank):
- pass
-
-
-class Nine(Rank):
- pass
-
-
-class Ten(Rank):
- pass
-
-
-class Ace(Rank):
- pass
-
-
-class King(Rank):
- pass
-
-
-class Queen(Rank):
- pass
-
-
-class Jack(Rank):
- pass
-
-
-class Hearts(Suit):
- pass
-
-
-class Clubs(Suit):
- pass
-
-
-class Spades(Suit):
- pass
-
-
-class Diamonds(Suit):
- pass
-
-
-RANKS = {klass: eval(klass) for klass in ORDERED_RANKS}
-
-
-SUITS = {klass: eval(klass) for klass in ORDERED_SUITS}
-
-
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
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.__collection = 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)
def __str__(self):
return str([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return self.__collection.__iter__()
def StandardDeck():
- return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ORDERED_RANKS]
-def BelotDeck():
- ranks = ORDERED_RANKS[0:7:]
- ranks.append('Ace')
- return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS[0:7:]
+def BeloteDeck():
+ ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Ace']
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
for rank in ranks]
def SixtySixDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
- return [Card(eval(rank), eval(suit)) for suit in ORDERED_SUITS[0:7:]
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
for rank in ranks]

Цветелина обнови решението на 21.03.2014 14:24 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__ == self.__class__
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'red'
else:
self.__color = 'black'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
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.__collection = 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)
def __str__(self):
- return str([str(card) for card in self.__collection])
+ return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return self.__collection.__iter__()
def StandardDeck():
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ORDERED_RANKS]
def BeloteDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Ace']
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
for rank in ranks]
def SixtySixDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
for rank in ranks]

Цветелина обнови решението на 21.03.2014 14:38 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__ == self.__class__
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'red'
else:
self.__color = 'black'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
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.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return self.__collection.__iter__()
def StandardDeck():
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ORDERED_RANKS]
def BeloteDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Ace']
- return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def SixtySixDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
- return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS[0:7:]
+ return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]

Цветелина обнови решението на 21.03.2014 14:57 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__ == self.__class__
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
- self.__color = 'red'
- else:
self.__color = 'black'
+ else:
+ self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
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.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return self.__collection.__iter__()
def StandardDeck():
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ORDERED_RANKS]
def BeloteDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Ace']
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def SixtySixDeck():
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]

Цветелина обнови решението на 21.03.2014 21:25 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
- return self.__class__ == self.__class__
+ return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
- return self.rank == other.rank and self.suit == other.suit
+ return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection:
def __init__(self, collection=[]):
self.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return self.__collection[index]
def __iter__(self):
return self.__collection.__iter__()
-def StandardDeck():
+def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
- for rank in ORDERED_RANKS]
+ for rank in ranks]
+def StandardDeck():
+ return make_deck(ORDERED_RANKS)
+
+
def BeloteDeck():
- ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Ace']
- return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
- for rank in ranks]
+ return make_deck(['King', 'Queen', 'Jack', 'Ten',
+ 'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
- ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
- return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
+ return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])
- for rank in ranks]

Цветелина обнови решението на 22.03.2014 21:22 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection:
def __init__(self, collection=[]):
self.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
- return self.__collection[index]
+ return str(self.__collection[index])
def __iter__(self):
return self.__collection.__iter__()
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

Цветелина обнови решението на 24.03.2014 00:31 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
-class CardCollection:
+class CardCollection(list):
def __init__(self, collection=[]):
- self.__collection = collection
+ list.__init__([])
+ self.extend(collection)
def draw(self, index):
- return self.__collection.pop(index)
+ return self.pop(index)
def draw_from_top(self):
- return self.__collection.pop(-1)
+ return self.pop(-1)
def draw_from_bottom(self):
- return self.__collection.pop(0)
+ return self.pop()
def top_card(self):
- return self.__collection[-1]
+ return self[-1]
def bottom_card(self):
- return self.__collection[0]
+ return self[0]
def add(self, card):
- self.__collection.append(card)
+ self.append(card)
def index(self, card):
- return self.__collection.index(card)
+ return self.index(card)
def __str__(self):
- return "{0}".format([str(card) for card in self.__collection])
-
- def __len__(self):
- return len(self.__collection)
-
- def __getitem__(self, index):
- return str(self.__collection[index])
-
- def __iter__(self):
- return self.__collection.__iter__()
+ return "{0}".format([str(card) for card in self])
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

Цветелина обнови решението на 24.03.2014 00:44 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection(list):
def __init__(self, collection=[]):
list.__init__([])
self.extend(collection)
def draw(self, index):
return self.pop(index)
def draw_from_top(self):
return self.pop(-1)
def draw_from_bottom(self):
return self.pop()
def top_card(self):
return self[-1]
def bottom_card(self):
return self[0]
def add(self, card):
self.append(card)
- def index(self, card):
- return self.index(card)
-
def __str__(self):
return "{0}".format([str(card) for card in self])
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

Цветелина обнови решението на 25.03.2014 20:18 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
-class CardCollection(list):
+class CardCollection:
def __init__(self, collection=[]):
- list.__init__([])
- self.extend(collection)
+ self.__collection = collection
def draw(self, index):
- return self.pop(index)
+ return self.__collection.pop(index)
def draw_from_top(self):
- return self.pop(-1)
+ return self.__collection.pop(-1)
def draw_from_bottom(self):
- return self.pop()
+ return self.__collection.pop(0)
def top_card(self):
- return self[-1]
+ return self.__collection[-1]
def bottom_card(self):
- return self[0]
+ return self.__collection[0]
def add(self, card):
- self.append(card)
+ self.__collection.append(card)
+ def index(self, card):
+ return self.__collection.index(card)
+
def __str__(self):
- return "{0}".format([str(card) for card in self])
+ return "{0}".format([str(card) for card in self.__collection])
+ def __len__(self):
+ return len(self.__collection)
+ def __getitem__(self, index):
+ return str(self.__collection[index])
+
+ def __iter__(self):
+ return self.__collection.__iter__()
+
+
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
- return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])
+ return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

Цветелина обнови решението на 26.03.2014 11:56 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection:
def __init__(self, collection=[]):
self.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
return str(self.__collection[index])
def __iter__(self):
- return self.__collection.__iter__()
+ return iter(self.__collection)
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])

Цветелина обнови решението на 26.03.2014 14:36 (преди над 10 години)

RANKS_SYMBOLS = ['K', 'Q', 'J', '10', '9', '8',
'7', '6', '5', '4', '3', '2', 'A']
ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class CardElement:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return str(self) == str(other)
class Suit(CardElement):
def __init__(self):
if ORDERED_SUITS.index(self.__class__.__name__) % 2:
self.__color = 'black'
else:
self.__color = 'red'
class Rank(CardElement):
def __init__(self):
index = ORDERED_RANKS.index(self.__class__.__name__)
self.__symbol = RANKS_SYMBOLS[index]
RANKS = {klass: type(klass, (Rank, ), {}) for klass in ORDERED_RANKS}
SUITS = {klass: type(klass, (Suit, ), {}) for klass in ORDERED_SUITS}
class Card:
def __init__(self, rank_class, suit_class):
self.__rank = rank_class()
self.__suit = suit_class()
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return str(self) == str(other)
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
class CardCollection:
def __init__(self, collection=[]):
self.__collection = 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)
def __str__(self):
return "{0}".format([str(card) for card in self.__collection])
def __len__(self):
return len(self.__collection)
def __getitem__(self, index):
- return str(self.__collection[index])
+ return self.__collection[index]
def __iter__(self):
return iter(self.__collection)
def make_deck(ranks):
return [Card(RANKS[rank], SUITS[suit]) for suit in ORDERED_SUITS
for rank in ranks]
def StandardDeck():
return make_deck(ORDERED_RANKS)
def BeloteDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace'])
def SixtySixDeck():
return make_deck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace'])