Решение на Тесте карти от Снежана Спасова

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

Към профила на Снежана Спасова

Резултати

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

Код

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
index = 0
for i in self.collection:
if i == card:
return index
index +=1
raise ValueError
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
print(deck)
return CardCollection(deck)
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
print(deck)
return CardCollection(deck)
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
print(deck)
return CardCollection(deck)

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

...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-v23lh2/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-v23lh2/test.py", line 135, in test_deck_order
    self.assertEqual(deck[1], card2)
AssertionError: <Card Three of Clubs> != <Card Three of Diamonds>

----------------------------------------------------------------------
Ran 16 tests in 0.044s

FAILED (failures=2)

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

Снежана обнови решението на 26.03.2014 02:56 (преди над 10 години)

+from collections import OrderedDict
+
+class Rank():
+ def __init__(self, symbol, view):
+ self.symbol = symbol
+ self.view = view
+ def __eq__(self, other):
+ return self.class_method() == other.class_method()
+
+ @classmethod
+ def class_method(cls):
+ return cls
+
+ def __repr__(self):
+ return str(self.view)
+
+class Suit():
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.class_method() == other.class_method()
+
+ @classmethod
+ def class_method(cls):
+ return cls
+
+class Two(Rank):
+ def __init__(self):
+ super(Two, self).__init__('2', "Two")
+
+class Three(Rank):
+ def __init__(self):
+ super(Three, self).__init__('3', "Three")
+
+class Four(Rank):
+ def __init__(self):
+ super(Four, self).__init__('4', "Four")
+
+class Five(Rank):
+ def __init__(self):
+ super(Five, self).__init__('5', "Five")
+
+class Six(Rank):
+ def __init__(self):
+ super(Six, self).__init__('6', "Six")
+
+class Seven(Rank):
+ def __init__(self):
+ super(Seven, self).__init__('7', "Seven")
+
+class Eight(Rank):
+ def __init__(self):
+ super(Eight, self).__init__('8', "Eight")
+
+class Nine(Rank):
+ def __init__(self):
+ super(Nine, self).__init__('9', "Nine")
+
+class Ten(Rank):
+ def __init__(self):
+ super(Ten, self).__init__('10', "Ten")
+
+class Jack(Rank):
+ def __init__(self):
+ super(Jack, self).__init__('J', "Jack")
+
+class Queen(Rank):
+ def __init__(self):
+ super(Queen, self).__init__('Q', "Queen")
+
+class King(Rank):
+ def __init__(self):
+ super(King, self).__init__('K', "King")
+
+class Ace(Rank):
+ def __init__(self):
+ super(Ace, self).__init__('A', "Ace")
+
+class Hearts(Suit):
+ def __init__(self):
+ super(Hearts, self).__init__('red')
+
+class Clubs(Suit):
+ def __init__(self):
+ super(Clubs, self).__init__('black')
+
+class Spades(Suit):
+ def __init__(self):
+ super(Spades, self).__init__('black')
+
+class Diamonds(Suit):
+ def __init__(self):
+ super(Diamonds, self).__init__('red')
+
+RANKS = OrderedDict([("Ace", Ace), ("Two", Two), ("Three", Three), ("Four", Four),
+ ("Five", Five), ("Six", Six), ("Seven", Seven), ("Eight", Eight),
+ ("Nine", Nine), ("Ten", Ten), ("Jack", Jack), ("Queen", Queen), ("King", King)])
+
+SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
+ ('Spades', Spades), ('Clubs', Clubs),])
+
+class Card():
+ def __init__(self, rank, suit):
+ self.__rank = rank.__call__()
+ self.__suit = suit.__call__()
+
+ @property
+ def rank(self):
+ return self.__rank
+
+ @property
+ def suit(self):
+ return self.__suit
+
+ @staticmethod
+ def find(dictionary, searched_value):
+ for key, value in dictionary.items():
+ if searched_value == value:
+ return key
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
+
+ def __repr__(self):
+ return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
+
+class CardCollection():
+ def __init__(self, collection = []):
+ self.collection = collection
+
+ def __len__(self):
+ return len(list(self.collection))
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ card = self.collection[index]
+ del self.collection[index]
+ return card
+
+ def draw_from_top(self):
+ card = self.collection[-1]
+ del self.collection[-1]
+ return card
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+
+def StandardDeck():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+def BeloteDeck():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank not in ["Two", "Three", "Four", "Five", "Six"]:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck
+
+def SixtySix():
+ deck = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
+ deck.append(Card(RANKS[rank], SUITS[suit]))
+ return deck

Снежана обнови решението на 26.03.2014 03:13 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
+
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red')
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black')
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black')
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red')
RANKS = OrderedDict([("Ace", Ace), ("Two", Two), ("Three", Three), ("Four", Four),
("Five", Five), ("Six", Six), ("Seven", Seven), ("Eight", Eight),
("Nine", Nine), ("Ten", Ten), ("Jack", Jack), ("Queen", Queen), ("King", King)])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
-
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
+ def draw_from_bottom(self):
+ card = self.collection[0]
+ del self.collection[0]
+ return card
+
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
-
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySix():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 03:20 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red')
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black')
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black')
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red')
-RANKS = OrderedDict([("Ace", Ace), ("Two", Two), ("Three", Three), ("Four", Four),
- ("Five", Five), ("Six", Six), ("Seven", Seven), ("Eight", Eight),
- ("Nine", Nine), ("Ten", Ten), ("Jack", Jack), ("Queen", Queen), ("King", King)])
+RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
+ ("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
+ ("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
+ ("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
+
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
+
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySix():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 10:55 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red')
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black')
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black')
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red')
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
('Spades', Spades), ('Clubs', Clubs),])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
-def SixtySix():
+def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 11:24 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
- def __init__(self, color):
+ def __init__(self, color, view):
self.color = color
+ self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
+ def __str__(self):
+ return self.view
+
+
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
- super(Hearts, self).__init__('red')
+ super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
- super(Clubs, self).__init__('black')
+ super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
- super(Spades, self).__init__('black')
+ super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
- super(Diamonds, self).__init__('red')
+ super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
-SUITS = OrderedDict([('Diamonds', Diamonds), ('Hearts', Hearts),
- ('Spades', Spades), ('Clubs', Clubs),])
+SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
+ ('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 13:17 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
+ def __iter__(self):
+ return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 13:22 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
- def __iter__(self):
- return map(lambda x: x, self.collection)
+ # def __iter__(self):
+ # return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
+ def index(self, card):
+ index = 0
+ for i in self.collection:
+ if i == card:
+ return index
+ index +=1
+ raise ValueError
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

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

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
- # def __iter__(self):
- # return map(lambda x: x, self.collection)
+ def __iter__(self):
+ return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
index = 0
for i in self.collection:
if i == card:
return index
index +=1
raise ValueError
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 13:32 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
-
+
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
-
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
-
+
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
-
+
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
-
+
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
-
+
@property
def rank(self):
return self.__rank
-
+
@property
def suit(self):
return self.__suit
-
+
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
-
+
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
-
+
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
index = 0
for i in self.collection:
if i == card:
return index
index +=1
raise ValueError
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
return deck

Снежана обнови решението на 26.03.2014 15:00 (преди над 10 години)

from collections import OrderedDict
class Rank():
def __init__(self, symbol, view):
self.symbol = symbol
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __repr__(self):
return str(self.view)
class Suit():
def __init__(self, color, view):
self.color = color
self.view = view
def __eq__(self, other):
return self.class_method() == other.class_method()
@classmethod
def class_method(cls):
return cls
def __str__(self):
return self.view
class Two(Rank):
def __init__(self):
super(Two, self).__init__('2', "Two")
class Three(Rank):
def __init__(self):
super(Three, self).__init__('3', "Three")
class Four(Rank):
def __init__(self):
super(Four, self).__init__('4', "Four")
class Five(Rank):
def __init__(self):
super(Five, self).__init__('5', "Five")
class Six(Rank):
def __init__(self):
super(Six, self).__init__('6', "Six")
class Seven(Rank):
def __init__(self):
super(Seven, self).__init__('7', "Seven")
class Eight(Rank):
def __init__(self):
super(Eight, self).__init__('8', "Eight")
class Nine(Rank):
def __init__(self):
super(Nine, self).__init__('9', "Nine")
class Ten(Rank):
def __init__(self):
super(Ten, self).__init__('10', "Ten")
class Jack(Rank):
def __init__(self):
super(Jack, self).__init__('J', "Jack")
class Queen(Rank):
def __init__(self):
super(Queen, self).__init__('Q', "Queen")
class King(Rank):
def __init__(self):
super(King, self).__init__('K', "King")
class Ace(Rank):
def __init__(self):
super(Ace, self).__init__('A', "Ace")
class Hearts(Suit):
def __init__(self):
super(Hearts, self).__init__('red', "Hearts")
class Clubs(Suit):
def __init__(self):
super(Clubs, self).__init__('black', "Clubs")
class Spades(Suit):
def __init__(self):
super(Spades, self).__init__('black', "Spades")
class Diamonds(Suit):
def __init__(self):
super(Diamonds, self).__init__('red', "Diamonds")
RANKS = OrderedDict([("King", King), ("Queen", Queen), ("Jack", Jack), ("Ten", Ten),
("Nine", Nine), ("Eight", Eight), ("Seven", Seven), ("Six", Six),
("Five", Five), ("Four", Four), ("Three", Three), ("Two", Two),
("Ace", Ace)])
SUITS = OrderedDict([('Diamonds', Diamonds),('Clubs', Clubs),
('Hearts', Hearts), ('Spades', Spades)])
class Card():
def __init__(self, rank, suit):
self.__rank = rank.__call__()
self.__suit = suit.__call__()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
@staticmethod
def find(dictionary, searched_value):
for key, value in dictionary.items():
if searched_value == value:
return key
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
def __repr__(self):
return "<Card {} of {}>".format(self.find(RANKS, self.rank), self.find(SUITS, self.suit))
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __len__(self):
return len(list(self.collection))
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return map(lambda x: x, self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
card = self.collection[index]
del self.collection[index]
return card
def draw_from_top(self):
card = self.collection[-1]
del self.collection[-1]
return card
def draw_from_bottom(self):
card = self.collection[0]
del self.collection[0]
return card
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
index = 0
for i in self.collection:
if i == card:
return index
index +=1
raise ValueError
def StandardDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
deck.append(Card(RANKS[rank], SUITS[suit]))
- return deck
+ print(deck)
+ return CardCollection(deck)
def BeloteDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
- return deck
+ print(deck)
+ return CardCollection(deck)
def SixtySixDeck():
deck = []
for suit in SUITS:
for rank in RANKS:
if rank not in ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]:
deck.append(Card(RANKS[rank], SUITS[suit]))
- return deck
+ print(deck)
+ return CardCollection(deck)