Решение на Тесте карти от Александър Чешмеджиев

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

Към профила на Александър Чешмеджиев

Резултати

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

Код

import collections
RANK_TO_SYMBOL = (('Ace', 'A'), ('Two', '2'), ('Three', '3'), ('Four', '4'),
('Five', '5'), ('Six', '6'), ('Seven', '7'), ('Eight', '8'),
('Nine', '9'), ('Ten', '10') , ('Jack', 'J'), ('Queen', 'Q'),
('King', 'K'))
class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
for rank in RANK_TO_SYMBOL:
if self.symbol == rank[1]:
return rank[0]
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.__class__ == other.__class__
def __str__(self):
for suit in SUIT_TO_CLASS:
if type(self) == suit[1]:
return suit[0]
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Diamonds(Suit):
def __init__(self):
self.color = 'red'
class Hearts(Suit):
def __init__(self):
self.color = 'red'
class Spades(Suit):
def __init__(self):
self.color = 'black'
class Clubs(Suit):
def __init__(self):
self.color = 'black'
ORDERED_RANKS = collections.OrderedDict()
ORDERED_RANKS['King'] = type(King())
ORDERED_RANKS['Queen'] = type(Queen())
ORDERED_RANKS['Jack'] = type(Jack())
ORDERED_RANKS['Ten'] = type(Ten())
ORDERED_RANKS['Nine'] = type(Nine())
ORDERED_RANKS['Eight'] = type(Eight())
ORDERED_RANKS['Seven'] = type(Seven())
ORDERED_RANKS['Six'] = type(Six())
ORDERED_RANKS['Five'] = type(Five())
ORDERED_RANKS['Four'] = type(Four())
ORDERED_RANKS['Three'] = type(Three())
ORDERED_RANKS['Two'] = type(Two())
ORDERED_RANKS['Ace'] = type(Ace())
RANKS = dict(ORDERED_RANKS)
ORDERED_SUITS = collections.OrderedDict()
ORDERED_SUITS['Diamonds'] = type(Diamonds())
ORDERED_SUITS['Clubs'] = type(Clubs())
ORDERED_SUITS['Hearts'] = type(Hearts())
ORDERED_SUITS['Spades'] = type(Spades())
SUITS = dict(ORDERED_SUITS)
SUIT_TO_CLASS = (('Diamonds', type(Diamonds())), ('Hearts', type(Hearts())),
('Spades', type(Spades())), ('Clubs', type(Clubs())))
class Card:
@property#.setter
def rank(self, value):
self._rank = value
@property#.setter
def suit(self, value):
self._suit = value
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 '{0} of {1}'.format(str(self._rank), str(self._suit))
class CardCollection:
def __init__(self, collection):
self._collection = collection
def draw(self, index):
for i in range(0, len(self._collection)):
if index == i:
result = self._collection[i]
self._collection.remove(self._collection[i])
return str(result)
def draw_from_top(self):
draw(self, len(self._collection) - 1)
def draw_from_bottom(self):
draw(self, 0)
def top_card(self):
return str(self._collection[len(self._collection)-1])
def bottom_card(self):
return str(self._collection[0])
def add(self, card):
self._collection.append(card)
def index(self, card):
index = 0
found_card = False
for collection_card in self._collection:
if collection_card == card:
return index
else:
index += 1
if found_card == False:
raise ValueError('<Card {0}> is not in list'.format(str(card)))
def __getitem__(self, index):
return str(self._collection[index])
def StandardDeck():
standard_deck = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
standard_deck.append('<Card {0} of {1}>'.format(rank, suit))
return standard_deck
def BeloteDeck():
belote_deck = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank == 'Six':
break
else:
belote_deck.append('<Card {0} of {1}>'.format(rank, suit))
return belote_deck
def SixtySixDeck():
sixty_six_deck = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank == 'Eight':
break
else:
sixty_six_deck.append('<Card {0} of {1}>'.format(rank, suit))
return sixty_six_deck

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

FEEEFEFFE.EE.EEF
======================================================================
ERROR: test_deck_add (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-1ep8l2m/test.py", line 117, in test_deck_add
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: test_deck_draw (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-1ep8l2m/test.py", line 141, in test_deck_draw
    self.assertEqual(card, deck.draw_from_top())
  File "/tmp/d20140407-19315-1ep8l2m/solution.py", line 173, in draw_from_top
    draw(self, len(self._collection) - 1)
NameError: global name 'draw' is not defined

======================================================================
ERROR: 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-1ep8l2m/test.py", line 154, in test_deck_index
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: 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-1ep8l2m/test.py", line 129, in test_deck_order
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: test_all_card_instances (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 67, in test_all_card_instances
    self.assertIsInstance(card.rank, rank)
TypeError: rank() missing 1 required positional argument: 'value'

======================================================================
ERROR: test_all_suits_ranks_equal (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 92, in test_all_suits_ranks_equal
    self.assertEqual(card.rank, rank())
TypeError: rank() missing 1 required positional argument: 'value'

======================================================================
ERROR: test_all_to_string (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 104, in test_all_to_string
    + " of " + str(card.suit))
TypeError: rank() missing 1 required positional argument: 'value'

======================================================================
ERROR: test_card_instance (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 60, in test_card_instance
    self.assertIsInstance(aos.rank, solution.RANKS["Ace"])
TypeError: rank() missing 1 required positional argument: 'value'

======================================================================
ERROR: test_suit_rank_equals (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 85, in test_suit_rank_equals
    self.assertEqual(aos.rank, solution.RANKS["Ace"]())
TypeError: rank() missing 1 required positional argument: 'value'

======================================================================
FAIL: test_belote_deck (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-1ep8l2m/test.py", line 175, in test_belote_deck
    self.assertEqual(BELOTE_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['<Card King of Diamonds>', '<...

First differing element 0:
King of Diamonds
<Card King of Diamonds>

First list contains 4 additional elements.
First extra element 28:
Nine of Spades

Diff is 2279 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_deck_iteration (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-1ep8l2m/test.py", line 167, in test_deck_iteration
    self.assertIsInstance(card, solution.Card)
AssertionError: "<class 'solution.Four'> of <class 'solution.Clubs'>" is not an instance of <class 'solution.Card'>

======================================================================
FAIL: test_sixtysix_deck (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-1ep8l2m/test.py", line 179, in test_sixtysix_deck
    self.assertEqual(SIXTY_SIX_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['<Card King of Diamonds>', '<...

First differing element 0:
King of Diamonds
<Card King of Diamonds>

First list contains 4 additional elements.
First extra element 20:
Jack of Spades

Diff is 1640 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_standard_deck (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-1ep8l2m/test.py", line 171, in test_standard_deck
    self.assertEqual(STANDARD_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['<Card King of Diamonds>', '<...

First differing element 0:
King of Diamonds
<Card King of Diamonds>

Diff is 3991 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_to_string (test.CardTest)
----------------------------------------------------------------------
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-1ep8l2m/test.py", line 97, in test_to_string
    self.assertEqual(str(aos), "Ace of Spades")
AssertionError: "<class 'solution.Ace'> of <class 'solution.Spades'>" != 'Ace of Spades'
- <class 'solution.Ace'> of <class 'solution.Spades'>
+ Ace of Spades


----------------------------------------------------------------------
Ran 16 tests in 0.370s

FAILED (failures=5, errors=9)

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

Александър обнови решението на 26.03.2014 00:31 (преди над 10 години)

+import collections
+
+RANK_TO_SYMBOL = (('Ace', 'A'), ('Two', '2'), ('Three', '3'), ('Four', '4'),
+ ('Five', '5'), ('Six', '6'), ('Seven', '7'), ('Eight', '8'),
+ ('Nine', '9'), ('Ten', '10') , ('Jack', 'J'), ('Queen', 'Q'),
+ ('King', 'K'))
+
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __str__(self):
+ for rank in RANK_TO_SYMBOL:
+ if self.symbol == rank[1]:
+ return rank[0]
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+ def __str__(self):
+ for suit in SUIT_TO_CLASS:
+ if type(self) == suit[1]:
+ return suit[0]
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = 'A'
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = '2'
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = '3'
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = '4'
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = '5'
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = '6'
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = '7'
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = '8'
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = '9'
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = '10'
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = 'J'
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = 'Q'
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = 'K'
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = 'red'
+
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = 'red'
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = 'black'
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = 'black'
+
+
+RANKS = collections.OrderedDict()
+
+RANKS['King'] = type(King())
+RANKS['Queen'] = type(Queen())
+RANKS['Jack'] = type(Jack())
+RANKS['Ten'] = type(Ten())
+RANKS['Nine'] = type(Nine())
+RANKS['Eight'] = type(Eight())
+RANKS['Seven'] = type(Seven())
+RANKS['Six'] = type(Six())
+RANKS['Five'] = type(Five())
+RANKS['Four'] = type(Four())
+RANKS['Three'] = type(Three())
+RANKS['Two'] = type(Two())
+RANKS['Ace'] = type(Ace())
+
+SUITS = collections.OrderedDict()
+
+SUITS['Diamonds'] = type(Diamonds())
+SUITS['Clubs'] = type(Clubs())
+SUITS['Hearts'] = type(Hearts())
+SUITS['Spades'] = type(Spades())
+
+
+SUIT_TO_CLASS = (('Diamonds', type(Diamonds())), ('Hearts', type(Hearts())),
+ ('Spades', type(Spades())), ('Clubs', type(Clubs())))
+
+
+class Card:
+ @property#.setter
+ def rank(self, value):
+ self._rank = value
+ @property#.setter
+ def suit(self, value):
+ self._suit = value
+ 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 '{0} of {1}'.format(str(self._rank), str(self._suit))
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self._collection = collection
+ def draw(self, index):
+ for i in range(0, len(self._collection)):
+ if index == i:
+ result = self._collection[i]
+ self._collection.remove(self._collection[i])
+ return str(result)
+ def draw_from_top(self):
+ draw(self, len(self._collection) - 1)
+ def draw_from_bottom(self):
+ draw(self, 0)
+ def top_card(self):
+ return str(self._collection[len(self._collection)-1])
+ def bottom_card(self):
+ return str(self._collection[0])
+ def add(self, card):
+ self._collection.append(card)
+ def index(self, card):
+ index = 0
+ found_card = False
+ for collection_card in self._collection:
+ if collection_card == card:
+ return index
+ else:
+ index += 1
+ if found_card == False:
+ raise ValueError('<Card {0}> is not in list'.format(str(card)))
+ def __getitem__(self, index):
+ return str(self._collection[index])
+
+def StandardDeck():
+ standard_deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ standard_deck.append('<Card {0} of {1}>'.format(rank, suit))
+ return standard_deck
+
+def BeloteDeck():
+ belote_deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank == 'Six':
+ break
+ else:
+ belote_deck.append('<Card {0} of {1}>'.format(rank, suit))
+ return belote_deck
+
+def SixtySixDeck():
+ sixty_six_deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank == 'Eight':
+ break
+ else:
+ sixty_six_deck.append('<Card {0} of {1}>'.format(rank, suit))
+ return sixty_six_deck
+

Александър обнови решението на 26.03.2014 00:49 (преди над 10 години)

import collections
RANK_TO_SYMBOL = (('Ace', 'A'), ('Two', '2'), ('Three', '3'), ('Four', '4'),
('Five', '5'), ('Six', '6'), ('Seven', '7'), ('Eight', '8'),
('Nine', '9'), ('Ten', '10') , ('Jack', 'J'), ('Queen', 'Q'),
('King', 'K'))
class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
for rank in RANK_TO_SYMBOL:
if self.symbol == rank[1]:
return rank[0]
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.__class__ == other.__class__
def __str__(self):
for suit in SUIT_TO_CLASS:
if type(self) == suit[1]:
return suit[0]
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Diamonds(Suit):
def __init__(self):
self.color = 'red'
class Hearts(Suit):
def __init__(self):
self.color = 'red'
class Spades(Suit):
def __init__(self):
self.color = 'black'
class Clubs(Suit):
def __init__(self):
self.color = 'black'
-RANKS = collections.OrderedDict()
+ORDERED_RANKS = collections.OrderedDict()
-RANKS['King'] = type(King())
-RANKS['Queen'] = type(Queen())
-RANKS['Jack'] = type(Jack())
-RANKS['Ten'] = type(Ten())
-RANKS['Nine'] = type(Nine())
-RANKS['Eight'] = type(Eight())
-RANKS['Seven'] = type(Seven())
-RANKS['Six'] = type(Six())
-RANKS['Five'] = type(Five())
-RANKS['Four'] = type(Four())
-RANKS['Three'] = type(Three())
-RANKS['Two'] = type(Two())
-RANKS['Ace'] = type(Ace())
+ORDERED_RANKS['King'] = type(King())
+ORDERED_RANKS['Queen'] = type(Queen())
+ORDERED_RANKS['Jack'] = type(Jack())
+ORDERED_RANKS['Ten'] = type(Ten())
+ORDERED_RANKS['Nine'] = type(Nine())
+ORDERED_RANKS['Eight'] = type(Eight())
+ORDERED_RANKS['Seven'] = type(Seven())
+ORDERED_RANKS['Six'] = type(Six())
+ORDERED_RANKS['Five'] = type(Five())
+ORDERED_RANKS['Four'] = type(Four())
+ORDERED_RANKS['Three'] = type(Three())
+ORDERED_RANKS['Two'] = type(Two())
+ORDERED_RANKS['Ace'] = type(Ace())
-SUITS = collections.OrderedDict()
+RANKS = dict(ORDERED_RANKS)
-SUITS['Diamonds'] = type(Diamonds())
-SUITS['Clubs'] = type(Clubs())
-SUITS['Hearts'] = type(Hearts())
-SUITS['Spades'] = type(Spades())
+ORDERED_SUITS = collections.OrderedDict()
+ORDERED_SUITS['Diamonds'] = type(Diamonds())
+ORDERED_SUITS['Clubs'] = type(Clubs())
+ORDERED_SUITS['Hearts'] = type(Hearts())
+ORDERED_SUITS['Spades'] = type(Spades())
+SUITS = dict(ORDERED_SUITS)
+
SUIT_TO_CLASS = (('Diamonds', type(Diamonds())), ('Hearts', type(Hearts())),
('Spades', type(Spades())), ('Clubs', type(Clubs())))
class Card:
@property#.setter
def rank(self, value):
self._rank = value
@property#.setter
def suit(self, value):
self._suit = value
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 '{0} of {1}'.format(str(self._rank), str(self._suit))
class CardCollection:
def __init__(self, collection):
self._collection = collection
def draw(self, index):
for i in range(0, len(self._collection)):
if index == i:
result = self._collection[i]
self._collection.remove(self._collection[i])
return str(result)
def draw_from_top(self):
draw(self, len(self._collection) - 1)
def draw_from_bottom(self):
draw(self, 0)
def top_card(self):
return str(self._collection[len(self._collection)-1])
def bottom_card(self):
return str(self._collection[0])
def add(self, card):
self._collection.append(card)
def index(self, card):
index = 0
found_card = False
for collection_card in self._collection:
if collection_card == card:
return index
else:
index += 1
if found_card == False:
raise ValueError('<Card {0}> is not in list'.format(str(card)))
def __getitem__(self, index):
return str(self._collection[index])
def StandardDeck():
standard_deck = []
- for suit in SUITS:
- for rank in RANKS:
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
standard_deck.append('<Card {0} of {1}>'.format(rank, suit))
return standard_deck
def BeloteDeck():
belote_deck = []
- for suit in SUITS:
- for rank in RANKS:
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
if rank == 'Six':
break
else:
belote_deck.append('<Card {0} of {1}>'.format(rank, suit))
return belote_deck
def SixtySixDeck():
sixty_six_deck = []
- for suit in SUITS:
- for rank in RANKS:
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
if rank == 'Eight':
break
else:
sixty_six_deck.append('<Card {0} of {1}>'.format(rank, suit))
return sixty_six_deck
-