Решение на От ливадите до Лас Вегас (и назад) от Сузана Петкова

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

Към профила на Сузана Петкова

Резултати

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

Код

import random
class Card:
def __init__(self, suit, face):
self._suit = suit
self._face = face
def get_suit(self):
return str(self._suit)
def get_face(self):
return str(self._face)
# def __repr__(self):
# return f'{self.face}, {self.suit}'
class Deck:
# deck = []
def __init__(self, face_filter=None):
self.face_filter = face_filter
self.deck = []
self.create()
# self.get_cards()
def create(self):
if self.face_filter is None:
list_of_cards = ['A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10']
else:
list_of_cards = self.face_filter
for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
for face in list_of_cards:
self.deck.append(Card(suit, face))
def cut(self):
n = random.randint(1, len(self.deck) - 1)
new_deck = self.deck[n:] + self.deck[:n]
self.deck = new_deck
def shuffle(self):
random.shuffle(self.deck)
def get_cards(self):
return self.deck
class Player:
def __init__(self):
self.cards = []
# self.get_cards()
def get_cards(self):
return self.cards
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions, filter_=None):
self.players = []
self.number_of_players = number_of_players
self.dealing_direction = dealing_direction
self.dealing_instructions = dealing_instructions
self.deck_for_game = Deck(filter_)
def get_players(self):
for _ in range(self.number_of_players):
self.players.append(Player())
return self.players
def prepare_deck(self):
for player in self.players:
if not player.cards == []:
# [self.deck_for_game.append(player_card) for player_card in self.]
self.deck_for_game.deck.extend(player.get_cards())
player.cards = []
self.deck_for_game.shuffle()
self.deck_for_game.cut()
def deal(self, player: Player):
start_index = self.players.index(player)
# number_of_cards = int(self.dealing_instructions.pop(0))
if self.dealing_direction == 'ltr':
direction_players = self.players[start_index:] + self.players[:start_index]
else:
direction_players = self.players[start_index::-1] + self.players[len(self.players):start_index:-1]
for count in self.dealing_instructions:
for player in direction_players:
for _ in range(count):
player.cards.append(self.deck_for_game.get_cards().pop())
def get_deck(self):
return self.deck_for_game
class Belot(Game):
def __init__(self):
Game.__init__(self, 4, 'ltr', (2, 3, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
class Poker(Game):
def __init__(self):
Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))

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

...............
----------------------------------------------------------------------
Ran 15 tests in 0.155s

OK

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

Сузана обнови решението на 08.11.2022 10:09 (преди около 2 години)

+import random
+
+
+class Card:
+
+ def __init__(self, suit, face):
+ self.suit = suit,
+ self.face = face,
+
+ def get_suit(self):
+ return str(self.suit)
+
+ def get_face(self):
+ return str(self.face)
+
+ # def __repr__(self):
+ # return f'{self.face}, {self.suit}'
+
+
+class Deck:
+ # deck = []
+
+ def __init__(self, face_filter=None):
+ self.face_filter = face_filter
+ self.deck = []
+ self.create()
+ # self.get_cards()
+
+ def create(self):
+ if self.face_filter is None:
+ for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
+ for face in ('A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10'):
+ self.deck.append(Card(suit, face))
+ else:
+ for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
+ for face in self.face_filter:
+ self.deck.append(Card(suit, face))
+
+ def cut(self):
+ n = random.randint(1, 51)
+ new_deck = self.deck[n:] + self.deck[:n]
+ self.deck = new_deck
+
+ def shuffle(self):
+ random.shuffle(self.deck)
+
+ def get_cards(self):
+ return self.deck
+
+
+class Player:
+
+ def __init__(self):
+ self.cards = []
+ self.get_cards()
+
+ def get_cards(self):
+ return self.cards
+
+
+class Game:
+ def __init__(self, number_of_players, dealing_direction, dealing_instructions, filter_=None):
+ self.players = []
+ self.number_of_players = number_of_players
+ self.dealing_direction = dealing_direction
+ self.dealing_instructions = list(dealing_instructions)
+ self.deck_for_game = Deck(filter_)
+
+ def get_players(self):
+ for i in range(self.number_of_players):
+ self.players.append(Player())
+ return self.players
+
+ def prepare_deck(self):
+ for player in self.players:
+ if not player.cards == []:
+ # [self.deck_for_game.append(player_card) for player_card in self.]
+ self.deck_for_game.deck.extend(player.get_cards())
+ self.deck_for_game.shuffle()
+ self.deck_for_game.cut()
+
+ def deal(self, player: Player):
+ start_index = self.players.index(player)
+ # number_of_cards = int(self.dealing_instructions.pop(0))
+ if self.dealing_direction == 'ltr':
+ direction_players = self.players[start_index:] + self.players[:start_index]
+ else:
+ direction_players = self.players[:start_index] + self.players[start_index:]
+ for count in self.dealing_instructions:
+ for player in direction_players:
+ for _ in range(count):
+ player.cards.append(self.deck_for_game.get_cards().pop())
+
+ def get_deck(self):
+ return self.deck_for_game
+
+
+class Belot(Game):
+ def __init__(self):
+ Game.__init__(self, 4, 'ltr', (3, 2, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
+
+
+class Poker(Game):
+ def __init__(self):
+ Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))

Сузана обнови решението на 12.11.2022 12:08 (преди около 2 години)

import random
class Card:
def __init__(self, suit, face):
- self.suit = suit,
- self.face = face,
+ self._suit = suit
+ self._face = face
def get_suit(self):
- return str(self.suit)
+ return str(self._suit)
def get_face(self):
- return str(self.face)
+ return str(self._face)
# def __repr__(self):
# return f'{self.face}, {self.suit}'
class Deck:
# deck = []
def __init__(self, face_filter=None):
self.face_filter = face_filter
self.deck = []
self.create()
# self.get_cards()
def create(self):
if self.face_filter is None:
- for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
- for face in ('A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10'):
- self.deck.append(Card(suit, face))
+ list_of_cards = ['A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10']
else:
- for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
- for face in self.face_filter:
- self.deck.append(Card(suit, face))
+ list_of_cards = self.face_filter
+ for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
+ for face in list_of_cards:
+ self.deck.append(Card(suit, face))
+
def cut(self):
- n = random.randint(1, 51)
+ n = random.randint(1, len(self.deck))
new_deck = self.deck[n:] + self.deck[:n]
self.deck = new_deck
def shuffle(self):
random.shuffle(self.deck)
def get_cards(self):
return self.deck
class Player:
def __init__(self):
self.cards = []
- self.get_cards()
+ # self.get_cards()
def get_cards(self):
return self.cards
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions, filter_=None):
self.players = []
self.number_of_players = number_of_players
self.dealing_direction = dealing_direction
- self.dealing_instructions = list(dealing_instructions)
+ self.dealing_instructions = dealing_instructions
self.deck_for_game = Deck(filter_)
def get_players(self):
- for i in range(self.number_of_players):
+ for _ in range(self.number_of_players):
self.players.append(Player())
return self.players
def prepare_deck(self):
for player in self.players:
if not player.cards == []:
# [self.deck_for_game.append(player_card) for player_card in self.]
self.deck_for_game.deck.extend(player.get_cards())
+ player.cards = []
self.deck_for_game.shuffle()
self.deck_for_game.cut()
def deal(self, player: Player):
start_index = self.players.index(player)
# number_of_cards = int(self.dealing_instructions.pop(0))
if self.dealing_direction == 'ltr':
direction_players = self.players[start_index:] + self.players[:start_index]
else:
direction_players = self.players[:start_index] + self.players[start_index:]
for count in self.dealing_instructions:
for player in direction_players:
for _ in range(count):
player.cards.append(self.deck_for_game.get_cards().pop())
def get_deck(self):
return self.deck_for_game
class Belot(Game):
def __init__(self):
Game.__init__(self, 4, 'ltr', (3, 2, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
class Poker(Game):
def __init__(self):
- Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))
+ Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))

Сузана обнови решението на 12.11.2022 12:12 (преди около 2 години)

import random
class Card:
def __init__(self, suit, face):
self._suit = suit
self._face = face
def get_suit(self):
return str(self._suit)
def get_face(self):
return str(self._face)
# def __repr__(self):
# return f'{self.face}, {self.suit}'
class Deck:
# deck = []
def __init__(self, face_filter=None):
self.face_filter = face_filter
self.deck = []
self.create()
# self.get_cards()
def create(self):
if self.face_filter is None:
list_of_cards = ['A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10']
else:
list_of_cards = self.face_filter
for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
for face in list_of_cards:
self.deck.append(Card(suit, face))
def cut(self):
- n = random.randint(1, len(self.deck))
+ n = random.randint(1, len(self.deck) - 1)
new_deck = self.deck[n:] + self.deck[:n]
self.deck = new_deck
def shuffle(self):
random.shuffle(self.deck)
def get_cards(self):
return self.deck
class Player:
def __init__(self):
self.cards = []
# self.get_cards()
def get_cards(self):
return self.cards
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions, filter_=None):
self.players = []
self.number_of_players = number_of_players
self.dealing_direction = dealing_direction
self.dealing_instructions = dealing_instructions
self.deck_for_game = Deck(filter_)
def get_players(self):
for _ in range(self.number_of_players):
self.players.append(Player())
return self.players
def prepare_deck(self):
for player in self.players:
if not player.cards == []:
# [self.deck_for_game.append(player_card) for player_card in self.]
self.deck_for_game.deck.extend(player.get_cards())
player.cards = []
self.deck_for_game.shuffle()
self.deck_for_game.cut()
def deal(self, player: Player):
start_index = self.players.index(player)
# number_of_cards = int(self.dealing_instructions.pop(0))
if self.dealing_direction == 'ltr':
direction_players = self.players[start_index:] + self.players[:start_index]
else:
direction_players = self.players[:start_index] + self.players[start_index:]
for count in self.dealing_instructions:
for player in direction_players:
for _ in range(count):
player.cards.append(self.deck_for_game.get_cards().pop())
def get_deck(self):
return self.deck_for_game
class Belot(Game):
def __init__(self):
Game.__init__(self, 4, 'ltr', (3, 2, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
class Poker(Game):
def __init__(self):
- Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))
+ Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))

Сузана обнови решението на 15.11.2022 12:19 (преди около 2 години)

import random
class Card:
def __init__(self, suit, face):
self._suit = suit
self._face = face
def get_suit(self):
return str(self._suit)
def get_face(self):
return str(self._face)
# def __repr__(self):
# return f'{self.face}, {self.suit}'
class Deck:
# deck = []
def __init__(self, face_filter=None):
self.face_filter = face_filter
self.deck = []
self.create()
# self.get_cards()
def create(self):
if self.face_filter is None:
list_of_cards = ['A', 'K', 'Q', 'J', '2', '3', '4', '5', '6', '7', '8', '9', '10']
else:
list_of_cards = self.face_filter
for suit in ('hearts', 'clubs', 'spades', 'diamonds'):
for face in list_of_cards:
self.deck.append(Card(suit, face))
def cut(self):
n = random.randint(1, len(self.deck) - 1)
new_deck = self.deck[n:] + self.deck[:n]
self.deck = new_deck
def shuffle(self):
random.shuffle(self.deck)
def get_cards(self):
return self.deck
class Player:
def __init__(self):
self.cards = []
# self.get_cards()
def get_cards(self):
return self.cards
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions, filter_=None):
self.players = []
self.number_of_players = number_of_players
self.dealing_direction = dealing_direction
self.dealing_instructions = dealing_instructions
self.deck_for_game = Deck(filter_)
def get_players(self):
for _ in range(self.number_of_players):
self.players.append(Player())
return self.players
def prepare_deck(self):
for player in self.players:
if not player.cards == []:
# [self.deck_for_game.append(player_card) for player_card in self.]
self.deck_for_game.deck.extend(player.get_cards())
player.cards = []
self.deck_for_game.shuffle()
self.deck_for_game.cut()
def deal(self, player: Player):
start_index = self.players.index(player)
# number_of_cards = int(self.dealing_instructions.pop(0))
if self.dealing_direction == 'ltr':
direction_players = self.players[start_index:] + self.players[:start_index]
else:
- direction_players = self.players[:start_index] + self.players[start_index:]
+
+ direction_players = self.players[start_index::-1] + self.players[len(self.players):start_index:-1]
+
for count in self.dealing_instructions:
for player in direction_players:
for _ in range(count):
player.cards.append(self.deck_for_game.get_cards().pop())
def get_deck(self):
return self.deck_for_game
class Belot(Game):
def __init__(self):
- Game.__init__(self, 4, 'ltr', (3, 2, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
+ Game.__init__(self, 4, 'ltr', (2, 3, 3), ['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
class Poker(Game):
def __init__(self):
- Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))
+ Game.__init__(self, 9, 'rtl', (1, 1, 1, 1, 1))