Решение на От ливадите до Лас Вегас (и назад) от Мария Симеонова

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

Към профила на Мария Симеонова

Резултати

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

Код

import random
class Card:
def __init__(self, suit, face):
self.suit = suit
self.face = face
def get_suit(self):
return self.suit
def get_face(self):
return self.face
class Deck:
def __init__(self, face_filter=None):
if face_filter is None:
face_filter = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
self.face_filter = face_filter
self.cards = []
for face in face_filter:
self.cards.append(Card('clubs', face))
self.cards.append(Card('diamonds', face))
self.cards.append(Card('hearts', face))
self.cards.append(Card('spades', face))
def cut(self):
length = random.randint(1, len(self.cards))
for card in range(length):
current_card = self.cards.pop()
self.cards.insert(0, current_card)
def shuffle(self):
random.shuffle(self.cards)
def get_cards(self):
return self.cards
class Player:
def __init__(self):
self.cards = []
def add_card(self, card):
self.cards.append(card)
def get_cards(self):
return self.cards
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions):
self.number_of_players = number_of_players
self.players = []
current_player = 0
while current_player < number_of_players:
self.players.append(Player())
current_player += 1
self.dealing_direction = dealing_direction
self.dealing_instructions = dealing_instructions
self.deck = Deck()
def get_players(self):
return self.players
def prepare_deck(self):
temporary_list = []
for player in self.players:
temporary_list.append(player.get_cards())
player.cards = []
for sublist_of_cards in temporary_list:
for card in sublist_of_cards:
self.deck.cards.append(card)
self.deck.shuffle()
self.deck.cut()
def deal(self, starting_player):
start = self.players.index(starting_player)
current_player = 0
if self.dealing_direction == 'ltr':
while current_player < start:
move_player = self.players[0]
self.players.pop(0)
self.players.append(move_player)
current_player += 1
elif self.dealing_direction == 'rtl':
while current_player <= start:
move_player = self.players[0]
self.players.pop(0)
self.players.append(move_player)
current_player += 1
self.players.reverse()
for num_of_cards in self.dealing_instructions:
for player in self.players:
given_cards = 0
while given_cards < num_of_cards:
player.add_card(self.deck.cards.pop(0))
given_cards += 1
def get_deck(self):
return self.deck.get_cards()
class Belot(Game):
def __init__(self):
self.number_of_players = 4
self.players = []
current_player = 0
while current_player < 4:
self.players.append(Player())
current_player += 1
self.dealing_direction = 'ltr'
self.dealing_instructions = (2, 3, 3)
self.deck = Deck(['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
class Poker(Game):
def __init__(self):
self.number_of_players = 9
self.players = []
current_player = 0
while current_player < 9:
self.players.append(Player())
current_player += 1
self.dealing_direction = 'rtl'
self.dealing_instructions = (1, 1, 1, 1, 1)
self.deck = Deck()

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

EE......EEE..EE
======================================================================
ERROR: test_correct_deck_init (test.TestBelot)
Test initialization with correct deck.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_correct_direction_and_players_deal (test.TestBelot)
Test dealing with correct direction and players.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_collecting_cards_before_dealing (test.TestGame)
Test collecting the cards before a new deal.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_dealing_ltr (test.TestGame)
Test dealing the cards left to right.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_dealing_rtl (test.TestGame)
Test dealing the cards right to left.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_correct_deck_init (test.TestPoker)
Test initialization with correct deck.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

======================================================================
ERROR: test_correct_direction_and_players_deal (test.TestPoker)
Test dealing with correct direction and players.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'list' object has no attribute 'get_cards'

----------------------------------------------------------------------
Ran 15 tests in 0.165s

FAILED (errors=7)

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

Мария обнови решението на 15.11.2022 01:40 (преди около 2 години)

+import random
+
+
+class Card:
+ def __init__(self, suit, face):
+ self.suit = suit
+ self.face = face
+
+ def get_suit(self):
+ return self.suit
+
+ def get_face(self):
+ return self.face
+
+
+class Deck:
+ def __init__(self, face_filter=None):
+ if face_filter is None:
+ face_filter = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
+ self.face_filter = face_filter
+ self.cards = []
+ for face in face_filter:
+ self.cards.append(Card('clubs', face))
+ self.cards.append(Card('diamonds', face))
+ self.cards.append(Card('hearts', face))
+ self.cards.append(Card('spades', face))
+
+ def cut(self):
+ length = random.randint(1, len(self.cards))
+ for card in range(length):
+ current_card = self.cards.pop()
+ self.cards.insert(0, current_card)
+
+ def shuffle(self):
+ random.shuffle(self.cards)
+
+ def get_cards(self):
+ return self.cards
+
+
+class Player:
+ def __init__(self):
+ self.cards = []
+
+ def add_card(self, card):
+ self.cards.append(card)
+
+ def get_cards(self):
+ return self.cards
+
+
+class Game:
+ def __init__(self, number_of_players, dealing_direction, dealing_instructions):
+ self.number_of_players = number_of_players
+ self.players = []
+ current_player = 0
+ while current_player < number_of_players:
+ self.players.append(Player())
+ current_player += 1
+ self.dealing_direction = dealing_direction
+ self.dealing_instructions = dealing_instructions
+ self.deck = Deck()
+
+ def get_players(self):
+ return self.players
+
+ def prepare_deck(self):
+ temporary_list = []
+ for player in self.players:
+ temporary_list.append(player.get_cards())
+ player.cards = []
+ for sublist_of_cards in temporary_list:
+ for card in sublist_of_cards:
+ self.deck.cards.append(card)
+ self.deck.shuffle()
+ self.deck.cut()
+
+ def deal(self, starting_player):
+ start = self.players.index(starting_player)
+ current_player = 0
+ if self.dealing_direction == 'ltr':
+ while current_player < start:
+ move_player = self.players[0]
+ self.players.pop(0)
+ self.players.append(move_player)
+ current_player += 1
+ elif self.dealing_direction == 'rtl':
+ while current_player <= start:
+ move_player = self.players[0]
+ self.players.pop(0)
+ self.players.append(move_player)
+ current_player += 1
+ self.players.reverse()
+ for num_of_cards in self.dealing_instructions:
+ for player in self.players:
+ given_cards = 0
+ while given_cards < num_of_cards:
+ player.add_card(self.deck.cards.pop(0))
+ given_cards += 1
+
+ def get_deck(self):
+ return self.deck.get_cards()
+
+
+class Belot(Game):
+ def __init__(self):
+ self.number_of_players = 4
+ self.players = []
+ current_player = 0
+ while current_player < 4:
+ self.players.append(Player())
+ current_player += 1
+ self.dealing_direction = 'ltr'
+ self.dealing_instructions = (2, 3, 3)
+ self.deck = Deck(['7', '8', '9', '10', 'J', 'Q', 'K', 'A'])
+
+
+class Poker(Game):
+ def __init__(self):
+ self.number_of_players = 9
+ self.players = []
+ current_player = 0
+ while current_player < 9:
+ self.players.append(Player())
+ current_player += 1
+ self.dealing_direction = 'rtl'
+ self.dealing_instructions = (1, 1, 1, 1, 1)
+ self.deck = Deck()