Решение на Тесте карти от Иван Върбанов

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

Към профила на Иван Върбанов

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 13 успешни тест(а)
  • 3 неуспешни тест(а)

Код

from collections import OrderedDict
STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace',
]
FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace',
]
SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return str(self.__class__.__name__)
class Suit:
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
def __str__(self):
return str(self.__class__.__name__)
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
('Five', Five), ('Queen', Queen), ('Ten', Ten),
('Ace', Ace), ('Three', Three), ('Eight', Eight),
('Four', Four), ('Two', Two), ('Seven', Seven),
('Nine', Nine),
])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),
])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return "{0} of {1}".format(self.rank.__class__.__name__,
self.suit.__class__.__name__,
)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
class CardCollection:
def __init__(self, collection=list()):
self.collection = collection
self.length = len(collection)
def __getitem__(self, i):
return (self.collection)[i]
def __iter__(self):
index = 0
while index < self.length:
yield self.collection[index]
index = index + 1
def add(self, card):
self.collection.append(card)
self.length = self.length + 1
def bottom_card(self):
return self.collection[0]
def top_card(self):
return self.collection[self.length-1]
def draw(self, index):
temporary = self.collection[index]
del self.collection[index]
self.length = self.length - 1
return temporary
def draw_from_top(self):
temporary = self.collection[self.length-1]
del self.collection[self.length-1]
self.length = self.length - 1
return temporary
def draw_from_bottom(self):
temporary = self.collection[0]
del self.collection[0]
self.length = self.length - 1
return temporary
def index(self, card):
if card in self.collection:
return self.collection.index(card)
else:
raise ValueError(str(card), ' is not in list')
def __len__(self):
return self.length
def StandardDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in STANDARTDECK_ORDERED_RANKS:
collection.append(str(Card(RANKS[rank], SUITS[suit])))
return collection
def BeloteDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in BELOTEDECK_ORDERED_RANKS:
collection.append(str(Card(RANKS[rank], SUITS[suit])))
return collection
def SixtySixDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in SIXTYSIXDECK_ORDERED_RANKS:
collection.append(str(Card(RANKS[rank], SUITS[suit])))
return collection

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

...F.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-u2vprn/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-u2vprn/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb7824c4c> != <solution.Card object at 0xb7837b0c>

======================================================================
FAIL: test_card_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-u2vprn/test.py", line 74, in test_card_equals
    self.assertNotEqual(aos1, solution.Card(solution.RANKS["Ace"], solution.SUITS["Hearts"]))
AssertionError: <solution.Card object at 0xb783c8ec> == <solution.Card object at 0xb783c94c>

----------------------------------------------------------------------
Ran 16 tests in 0.023s

FAILED (failures=3)

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

Иван обнови решението на 25.03.2014 23:05 (преди над 10 години)

+from collections import OrderedDict
+
+STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
+ 'Eight', 'Seven', 'Six', 'Five', 'Four',
+ 'Three', 'Two', 'Ace',
+ ]
+FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
+ 'Nine', 'Eight', 'Seven', 'Ace',
+ ]
+
+SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+
+
+class Rank:
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return str(self.__class__.__name__)
+
+
+class Suit:
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return str(self.__class__.__name__)
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
+ ('Five', Five), ('Queen', Queen), ('Ten', Ten),
+ ('Ace', Ace), ('Three', Three), ('Eight', Eight),
+ ('Four', Four), ('Two', Two), ('Seven', Seven),
+ ('Nine', Nine),
+ ])
+SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
+ ('Spades', Spades), ('Clubs', Clubs),
+ ])
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __eq__(self, other):
+ return self.rank == other.rank
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank.__class__.__name__,
+ self.suit.__class__.__name__
+ )
+
+ def __setattr__(self, *args):
+ raise AttributeError("can't set attribute")
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = collection
+ self.length = len(collection)
+ self.num = 0
+
+ def __getitem__(self, i):
+ return (self.collection)[i]
+
+ def __iter__(self):
+ while self.num < self.length:
+ yield self.collection[self.num]
+ self.num = self.num + 1
+
+ def add(self, card):
+ self.collection.append(card)
+ self.length = self.length + 1
+
+ def bottom_card(self):
+ return self.collection[self.num]
+
+ def top_card(self):
+ return self.collection[self.length-1]
+
+ def draw(self, index):
+ temporary = self.collection[index]
+ del self.collection[index]
+ self.length = self.length - 1
+ return temporary
+
+ def draw_from_top(self):
+ temporary = self.collection[self.length-1]
+ del self.collection[self.length-1]
+ self.length = self.length - 1
+ return temporary
+
+ def draw_from_bottom(self):
+ temporary = self.collection[self.num]
+ del self.collection[self.num]
+ self.length = self.length - 1
+ return temporary
+
+ def index(self, card):
+ if card in self.collection:
+ return self.collection.index(card)
+ else:
+ raise ValueError(str(card), ' is not in list')
+
+ def __len__(self):
+ return self.length
+
+
+def StandardDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in STANDARTDECK_ORDERED_RANKS:
+ collection.append(Card(rank, suit))
+ return CardCollection(collection)
+
+
+def BeloteDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in BELOTEDECK_ORDERED_RANKS:
+ collection.appends(Card(rank, suit))
+ return CardCollection(collection)
+
+
+def SixtySixDeck():
+ collection = []
+ for suit in FUNCTIONS_ORDERED_SUITS:
+ for rank in SIXTYSIXDECK_ORDERED_RANKS:
+ collection.append(Card(rank, suit))
+ return CardCollection(collection)

Иван обнови решението на 26.03.2014 11:17 (преди над 10 години)

from collections import OrderedDict
STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace',
]
FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace',
]
SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return str(self.__class__.__name__)
class Suit:
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return str(self.__class__.__name__)
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
('Five', Five), ('Queen', Queen), ('Ten', Ten),
('Ace', Ace), ('Three', Three), ('Eight', Eight),
('Four', Four), ('Two', Two), ('Seven', Seven),
('Nine', Nine),
])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),
])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return "{0} of {1}".format(self.rank.__class__.__name__,
self.suit.__class__.__name__
)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
class CardCollection:
- def __init__(self, collection):
+ def __init__(self, collection=list()):
self.collection = collection
self.length = len(collection)
- self.num = 0
def __getitem__(self, i):
return (self.collection)[i]
def __iter__(self):
- while self.num < self.length:
- yield self.collection[self.num]
- self.num = self.num + 1
+ index = 0
+ while index < self.length:
+ yield self.collection[index]
+ index = index + 1
def add(self, card):
self.collection.append(card)
self.length = self.length + 1
def bottom_card(self):
- return self.collection[self.num]
+ return self.collection[0]
def top_card(self):
return self.collection[self.length-1]
def draw(self, index):
temporary = self.collection[index]
del self.collection[index]
self.length = self.length - 1
return temporary
def draw_from_top(self):
temporary = self.collection[self.length-1]
del self.collection[self.length-1]
self.length = self.length - 1
return temporary
def draw_from_bottom(self):
- temporary = self.collection[self.num]
- del self.collection[self.num]
+ temporary = self.collection[0]
+ del self.collection[0]
self.length = self.length - 1
return temporary
def index(self, card):
if card in self.collection:
return self.collection.index(card)
else:
raise ValueError(str(card), ' is not in list')
def __len__(self):
return self.length
def StandardDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in STANDARTDECK_ORDERED_RANKS:
collection.append(Card(rank, suit))
return CardCollection(collection)
def BeloteDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in BELOTEDECK_ORDERED_RANKS:
collection.appends(Card(rank, suit))
return CardCollection(collection)
def SixtySixDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in SIXTYSIXDECK_ORDERED_RANKS:
collection.append(Card(rank, suit))
return CardCollection(collection)

Иван обнови решението на 26.03.2014 12:18 (преди над 10 години)

from collections import OrderedDict
STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace',
]
FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace',
]
SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return str(self.__class__.__name__)
class Suit:
def __eq__(self, other):
- return self.color == other.color
+ return self.__class__.__name__ == other.__class__.__name__
def __str__(self):
return str(self.__class__.__name__)
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
('Five', Five), ('Queen', Queen), ('Ten', Ten),
('Ace', Ace), ('Three', Three), ('Eight', Eight),
('Four', Four), ('Two', Two), ('Seven', Seven),
('Nine', Nine),
])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),
])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return "{0} of {1}".format(self.rank.__class__.__name__,
self.suit.__class__.__name__
)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
class CardCollection:
def __init__(self, collection=list()):
self.collection = collection
self.length = len(collection)
def __getitem__(self, i):
return (self.collection)[i]
def __iter__(self):
index = 0
while index < self.length:
yield self.collection[index]
index = index + 1
def add(self, card):
self.collection.append(card)
self.length = self.length + 1
def bottom_card(self):
return self.collection[0]
def top_card(self):
return self.collection[self.length-1]
def draw(self, index):
temporary = self.collection[index]
del self.collection[index]
self.length = self.length - 1
return temporary
def draw_from_top(self):
temporary = self.collection[self.length-1]
del self.collection[self.length-1]
self.length = self.length - 1
return temporary
def draw_from_bottom(self):
temporary = self.collection[0]
del self.collection[0]
self.length = self.length - 1
return temporary
def index(self, card):
if card in self.collection:
return self.collection.index(card)
else:
raise ValueError(str(card), ' is not in list')
def __len__(self):
return self.length
def StandardDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in STANDARTDECK_ORDERED_RANKS:
collection.append(Card(rank, suit))
return CardCollection(collection)
def BeloteDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in BELOTEDECK_ORDERED_RANKS:
- collection.appends(Card(rank, suit))
+ collection.append(Card(rank, suit))
return CardCollection(collection)
def SixtySixDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in SIXTYSIXDECK_ORDERED_RANKS:
collection.append(Card(rank, suit))
return CardCollection(collection)

Иван обнови решението на 26.03.2014 12:28 (преди над 10 години)

from collections import OrderedDict
STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace',
]
FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace',
]
SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return str(self.__class__.__name__)
class Suit:
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
def __str__(self):
return str(self.__class__.__name__)
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
('Five', Five), ('Queen', Queen), ('Ten', Ten),
('Ace', Ace), ('Three', Three), ('Eight', Eight),
('Four', Four), ('Two', Two), ('Seven', Seven),
('Nine', Nine),
])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),
])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return "{0} of {1}".format(self.rank.__class__.__name__,
self.suit.__class__.__name__
)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
class CardCollection:
def __init__(self, collection=list()):
self.collection = collection
self.length = len(collection)
def __getitem__(self, i):
return (self.collection)[i]
def __iter__(self):
index = 0
while index < self.length:
yield self.collection[index]
index = index + 1
def add(self, card):
self.collection.append(card)
self.length = self.length + 1
def bottom_card(self):
return self.collection[0]
def top_card(self):
return self.collection[self.length-1]
def draw(self, index):
temporary = self.collection[index]
del self.collection[index]
self.length = self.length - 1
return temporary
def draw_from_top(self):
temporary = self.collection[self.length-1]
del self.collection[self.length-1]
self.length = self.length - 1
return temporary
def draw_from_bottom(self):
temporary = self.collection[0]
del self.collection[0]
self.length = self.length - 1
return temporary
def index(self, card):
if card in self.collection:
return self.collection.index(card)
else:
raise ValueError(str(card), ' is not in list')
def __len__(self):
return self.length
def StandardDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in STANDARTDECK_ORDERED_RANKS:
- collection.append(Card(rank, suit))
+ collection.append(Card(RANKS[rank], SUITS[suit]))
return CardCollection(collection)
def BeloteDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in BELOTEDECK_ORDERED_RANKS:
- collection.append(Card(rank, suit))
+ collection.append(Card(RANKS[rank], SUITS[suit]))
return CardCollection(collection)
def SixtySixDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in SIXTYSIXDECK_ORDERED_RANKS:
- collection.append(Card(rank, suit))
+ collection.append(Card(RANKS[rank], SUITS[suit]))
return CardCollection(collection)

Иван обнови решението на 26.03.2014 13:23 (преди над 10 години)

from collections import OrderedDict
STANDARTDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine',
'Eight', 'Seven', 'Six', 'Five', 'Four',
'Three', 'Two', 'Ace',
]
FUNCTIONS_ORDERED_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTEDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten',
'Nine', 'Eight', 'Seven', 'Ace',
]
SIXTYSIXDECK_ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return str(self.__class__.__name__)
class Suit:
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
def __str__(self):
return str(self.__class__.__name__)
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
RANKS = OrderedDict([('King', King), ('Six', Six), ('Jack', Jack),
('Five', Five), ('Queen', Queen), ('Ten', Ten),
('Ace', Ace), ('Three', Three), ('Eight', Eight),
('Four', Four), ('Two', Two), ('Seven', Seven),
('Nine', Nine),
])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),
])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __eq__(self, other):
return self.rank == other.rank
def __str__(self):
return "{0} of {1}".format(self.rank.__class__.__name__,
- self.suit.__class__.__name__
+ self.suit.__class__.__name__,
)
def __setattr__(self, *args):
raise AttributeError("can't set attribute")
class CardCollection:
def __init__(self, collection=list()):
self.collection = collection
self.length = len(collection)
def __getitem__(self, i):
return (self.collection)[i]
def __iter__(self):
index = 0
while index < self.length:
yield self.collection[index]
index = index + 1
def add(self, card):
self.collection.append(card)
self.length = self.length + 1
def bottom_card(self):
return self.collection[0]
def top_card(self):
return self.collection[self.length-1]
def draw(self, index):
temporary = self.collection[index]
del self.collection[index]
self.length = self.length - 1
return temporary
def draw_from_top(self):
temporary = self.collection[self.length-1]
del self.collection[self.length-1]
self.length = self.length - 1
return temporary
def draw_from_bottom(self):
temporary = self.collection[0]
del self.collection[0]
self.length = self.length - 1
return temporary
def index(self, card):
if card in self.collection:
return self.collection.index(card)
else:
raise ValueError(str(card), ' is not in list')
def __len__(self):
return self.length
def StandardDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in STANDARTDECK_ORDERED_RANKS:
- collection.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(collection)
+ collection.append(str(Card(RANKS[rank], SUITS[suit])))
+ return collection
def BeloteDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in BELOTEDECK_ORDERED_RANKS:
- collection.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(collection)
+ collection.append(str(Card(RANKS[rank], SUITS[suit])))
+ return collection
def SixtySixDeck():
collection = []
for suit in FUNCTIONS_ORDERED_SUITS:
for rank in SIXTYSIXDECK_ORDERED_RANKS:
- collection.append(Card(RANKS[rank], SUITS[suit]))
- return CardCollection(collection)
+ collection.append(str(Card(RANKS[rank], SUITS[suit])))
+ return collection