Решение на Тесте карти от Гергана Петрова

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

Към профила на Гергана Петрова

Резултати

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

Код

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
symbol = 'K'
class Six(Rank):
symbol = '6'
class Jack(Rank):
symbol = 'J'
class Five(Rank):
symbol = '5'
class Queen(Rank):
symbol = 'Q'
class Ten(Rank):
symbol = '10'
class Ace(Rank):
symbol = 'A'
class Three(Rank):
symbol = '3'
class Eight(Rank):
symbol = '8'
class Four(Rank):
symbol = '4'
class Two(Rank):
symbol = '2'
class Seven(Rank):
symbol = '7'
class Nine(Rank):
symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return type(self) == type(other)
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=()):
self.deck = list(collection)
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
return self.deck.pop(index)
def draw_from_top(self):
return self.draw(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[-1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
STANDARD_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
def StandardDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in STANDARD_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.019s

OK

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

Гергана обнови решението на 21.03.2014 16:46 (преди над 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = 'K'
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = '6'
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = 'J'
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = '5'
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = 'Q'
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = '10'
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = 'A'
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = '3'
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = '8'
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = '4'
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = '2'
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = '7'
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = '9'
+
+
+RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
+ [King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight, Four, Two, Seven, Nine]))
+
+
+class Suit:
+ def __init__(self, colour):
+ self.color = colour
+
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+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'
+
+
+SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'], [Diamonds, Hearts, Spades, Clubs]))
+
+
+class Card(Rank, Suit):
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+
+ def __str__(self):
+ return '%s of %s' % (self.rank, self.suit)
+
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+ def __setattr_(self, *args):
+ raise AttributeError
+
+class CardCollection:
+ def __init__(self, collection = []):
+ self.deck = collection
+
+
+ def __getitem__(self, index):
+ return self.deck[index]
+
+
+ def __len__(self):
+ return len(self.deck)
+
+
+ def draw(self, index):
+ card = self[index]
+ self.deck.remove(card)
+ return card
+
+
+ def draw_from_top(self):
+ return self.draw(len(self) - 1)
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+
+ def top_card(self):
+ return self.deck[len(self) - 1]
+
+
+ def bottom_card(self):
+ return self.deck[0]
+
+
+ def add(self, card):
+ self.deck.append(card)
+
+
+ def index(self, card):
+ return self.deck.index(card)

Гергана обнови решението на 21.03.2014 16:50 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight, Four, Two, Seven, Nine]))
class Suit:
def __init__(self, colour):
self.color = colour
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'], [Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
- def __setattr_(self, *args):
- raise AttributeError
-
class CardCollection:
def __init__(self, collection = []):
self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def draw(self, index):
card = self[index]
self.deck.remove(card)
return card
def draw_from_top(self):
return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[len(self) - 1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)

Гергана обнови решението на 21.03.2014 18:11 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
-
def __eq__(self, other):
return self.symbol == other.symbol
-
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
-RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
- [King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight, Four, Two, Seven, Nine]))
+RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
+ 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
+ [King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
+ Four, Two, Seven, Nine]))
class Suit:
def __init__(self, colour):
self.color = colour
-
def __str__(self):
return self.__class__.__name__
-
def __eq__(self, other):
return self.color == other.color
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'
-SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'], [Diamonds, Hearts, Spades, Clubs]))
+SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
+ [Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
-
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
-
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
- def __init__(self, collection = []):
- self.deck = collection
+ def __init__(self, collection=[]):
+ self.deck = collection
-
def __getitem__(self, index):
return self.deck[index]
-
def __len__(self):
return len(self.deck)
-
def draw(self, index):
card = self[index]
self.deck.remove(card)
return card
-
def draw_from_top(self):
- return self.draw(len(self) - 1)
+ return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
-
def top_card(self):
return self.deck[len(self) - 1]
-
def bottom_card(self):
return self.deck[0]
-
def add(self, card):
self.deck.append(card)
-
def index(self, card):
- return self.deck.index(card)
+ return self.deck.index(card)

Гергана обнови решението на 21.03.2014 23:11 (преди над 10 години)

class Rank:
- def __init__(self, symbol):
- self.symbol = symbol
-
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
- def __init__(self, colour):
- self.color = colour
-
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
- self.rank = rank()
- self.suit = suit()
+ self._rank = rank()
+ self._suit = suit()
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
+ def __repr__(self):
+ return '%s of %s' % (self.rank, self.suit)
+
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
- def __init__(self, collection=[]):
- self.deck = collection
+ def __init__(self, collection=None):
+ if collection is None:
+ self.deck = []
+ else:
+ self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
+ def __str__(self):
+ return str(self.deck)
+
def draw(self, index):
card = self[index]
self.deck.remove(card)
return card
def draw_from_top(self):
return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[len(self) - 1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
- return self.deck.index(card)
+ return self.deck.index(card)
+
+
+STANDART_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
+ Seven, Six, Five, Four, Three, Two, Ace]
+
+BELOT_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
+
+SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
+
+DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
+
+
+def StandartDeck():
+ return CardCollection([Card(rank, suit) for suit in DECK_SUITS
+ for rank in STANDART_DECK_RANKS])
+
+
+def BeloteDeck():
+ return CardCollection([Card(rank, suit) for suit in DECK_SUITS
+ for rank in BELOT_DECK_RANKS])
+
+
+def SixtySixDeck():
+ return CardCollection([Card(rank, suit) for suit in DECK_SUITS
+ for rank in SIXTY_SIX__DECK_RANKS])

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

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=None):
if collection is None:
self.deck = []
else:
self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
card = self[index]
self.deck.remove(card)
return card
def draw_from_top(self):
return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[len(self) - 1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
STANDART_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
-BELOT_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
+BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
def StandartDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in STANDART_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
- for rank in BELOT_DECK_RANKS])
+ for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])

Гергана обнови решението на 22.03.2014 11:30 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=None):
if collection is None:
self.deck = []
else:
self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
- card = self[index]
- self.deck.remove(card)
- return card
+ return self.deck.pop(index)
def draw_from_top(self):
return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[len(self) - 1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
STANDART_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
def StandartDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in STANDART_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])

Гергана обнови решението на 22.03.2014 13:04 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=None):
if collection is None:
self.deck = []
else:
self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
return self.deck.pop(index)
def draw_from_top(self):
return self.draw(len(self) - 1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[len(self) - 1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
-STANDART_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
+STANDARD_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
-def StandartDeck():
+def StandardDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
- for rank in STANDART_DECK_RANKS])
+ for rank in STANDARD_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])

Гергана обнови решението на 22.03.2014 13:12 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self):
self.symbol = 'K'
class Six(Rank):
def __init__(self):
self.symbol = '6'
class Jack(Rank):
def __init__(self):
self.symbol = 'J'
class Five(Rank):
def __init__(self):
self.symbol = '5'
class Queen(Rank):
def __init__(self):
self.symbol = 'Q'
class Ten(Rank):
def __init__(self):
self.symbol = '10'
class Ace(Rank):
def __init__(self):
self.symbol = 'A'
class Three(Rank):
def __init__(self):
self.symbol = '3'
class Eight(Rank):
def __init__(self):
self.symbol = '8'
class Four(Rank):
def __init__(self):
self.symbol = '4'
class Two(Rank):
def __init__(self):
self.symbol = '2'
class Seven(Rank):
def __init__(self):
self.symbol = '7'
class Nine(Rank):
def __init__(self):
self.symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.color == other.color
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'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=None):
if collection is None:
self.deck = []
else:
self.deck = collection
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
return self.deck.pop(index)
def draw_from_top(self):
- return self.draw(len(self) - 1)
+ return self.draw(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
- return self.deck[len(self) - 1]
+ return self.deck[-1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
STANDARD_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
def StandardDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in STANDARD_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])

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

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class King(Rank):
- def __init__(self):
- self.symbol = 'K'
+ symbol = 'K'
class Six(Rank):
- def __init__(self):
- self.symbol = '6'
+ symbol = '6'
class Jack(Rank):
- def __init__(self):
- self.symbol = 'J'
+ symbol = 'J'
class Five(Rank):
- def __init__(self):
- self.symbol = '5'
+ symbol = '5'
class Queen(Rank):
- def __init__(self):
- self.symbol = 'Q'
+ symbol = 'Q'
class Ten(Rank):
- def __init__(self):
- self.symbol = '10'
+ symbol = '10'
class Ace(Rank):
- def __init__(self):
- self.symbol = 'A'
+ symbol = 'A'
class Three(Rank):
- def __init__(self):
- self.symbol = '3'
+ symbol = '3'
class Eight(Rank):
- def __init__(self):
- self.symbol = '8'
+ symbol = '8'
class Four(Rank):
- def __init__(self):
- self.symbol = '4'
+ symbol = '4'
class Two(Rank):
- def __init__(self):
- self.symbol = '2'
+ symbol = '2'
class Seven(Rank):
- def __init__(self):
- self.symbol = '7'
+ symbol = '7'
class Nine(Rank):
- def __init__(self):
- self.symbol = '9'
+ symbol = '9'
RANKS = dict(zip(['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace',
'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine'],
[King, Six, Jack, Five, Queen, Ten, Ace, Three, Eight,
Four, Two, Seven, Nine]))
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
- return self.color == other.color
+ return type(self) == type(other)
class Diamonds(Suit):
- def __init__(self):
- self.color = 'red'
+ color = 'red'
class Hearts(Suit):
- def __init__(self):
- self.color = 'red'
+ color = 'red'
class Spades(Suit):
- def __init__(self):
- self.color = 'black'
+ color = 'black'
class Clubs(Suit):
- def __init__(self):
- self.color = 'black'
+ color = 'black'
SUITS = dict(zip(['Diamonds', 'Hearts', 'Spades', 'Clubs'],
[Diamonds, Hearts, Spades, Clubs]))
class Card(Rank, Suit):
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __repr__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
- def __init__(self, collection=None):
- if collection is None:
- self.deck = []
- else:
- self.deck = collection
+ def __init__(self, collection=()):
+ self.deck = list(collection)
def __getitem__(self, index):
return self.deck[index]
def __len__(self):
return len(self.deck)
def __str__(self):
return str(self.deck)
def draw(self, index):
return self.deck.pop(index)
def draw_from_top(self):
return self.draw(-1)
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self.deck[-1]
def bottom_card(self):
return self.deck[0]
def add(self, card):
self.deck.append(card)
def index(self, card):
return self.deck.index(card)
STANDARD_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight,
Seven, Six, Five, Four, Three, Two, Ace]
BELOTE_DECK_RANKS = [King, Queen, Jack, Ten, Nine, Eight, Seven, Ace]
SIXTY_SIX__DECK_RANKS = [King, Queen, Jack, Ten, Nine, Ace]
DECK_SUITS = [Diamonds, Clubs, Hearts, Spades]
def StandardDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in STANDARD_DECK_RANKS])
def BeloteDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in BELOTE_DECK_RANKS])
def SixtySixDeck():
return CardCollection([Card(rank, suit) for suit in DECK_SUITS
for rank in SIXTY_SIX__DECK_RANKS])