Решение на От ливадите до Лас Вегас (и назад) от Тихомир Божков

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

Към профила на Тихомир Божков

Резултати

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

Код

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):
self.deck = []
if face_filter == None:
for suit in ['clubs', 'diamonds', 'hearts', 'spades']:
for face in ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', ]:
self.deck.append(Card(suit, face))
else:
for suit in ['clubs', 'diamonds', 'hearts', 'spades']:
for face in face_filter:
self.deck.append(Card(suit, face))
def cut(self):
cards_wanted_to_draw = []
cards_wanted_to_draw.append(self.deck.pop())
number_of_drawed_cards = len(cards_wanted_to_draw)
self.deck.append(self.deck.pop(self.deck.index(number_of_drawed_cards)))
def shuffle(self):
random.shuffle(self.deck)
def get_cards(self):
return self.deck
class Player:
def get_cards():

get_cards е методът, който ще използваме, за да вземем картите, които вече си инстанцирал. Това не е метод за инстанциране на карти. Класът ти трябва да работи и без да извиквам този метод.

player_hand = []
for card in Deck.deck.deal():
player_hand.append()
return player_hand
class Game:
def __init__(self, number_of_players, dealing_direction, dealing_instructions):
self.number_of_players = number_of_players
self.dealing_direction = dealing_direction
self.dealing_instructions = dealing_instructions
def get_players(self):
self.num_players = self.number_of_players
for self.player in range(self.num_players):
self.list_of_players.append(self.player)
return self.list_of_players
def prepare_deck(self):
Deck.deck.append(Player.get_cards())
Deck.deck.shuffle()
Deck.deck.cut()
class Belot(Game):
def __init__(self):
Game(4, 'ltr', (2, 3, 3))
class Poker(Game):
def __init__():
Game(9, 'rtl', (1, 1, 1, 1, 1))

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

EE..E.EEEEEEEEE
======================================================================
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: 'Belot' object has no attribute 'get_deck'

======================================================================
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: 'Belot' object has no attribute 'get_deck'

======================================================================
ERROR: test_cutting_deck (test.TestDeck)
Test cutting a 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
ValueError: 1 is not in list

======================================================================
ERROR: test_init_regular (test.TestDeck)
Test initialized cards without filter.
----------------------------------------------------------------------
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
TypeError: Deck.__init__() missing 1 required positional argument: 'face_filter'

======================================================================
ERROR: test_shuffling_deck (test.TestDeck)
Test shuffling a 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
TypeError: Deck.__init__() missing 1 required positional argument: 'face_filter'

======================================================================
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
NameError: name 'list_of_players' is not defined

======================================================================
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
NameError: name 'list_of_players' is not defined

======================================================================
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
NameError: name 'list_of_players' is not defined

======================================================================
ERROR: test_players_creation (test.TestGame)
Test creation and retrieval of 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
NameError: name 'list_of_players' is not defined

======================================================================
ERROR: test_prepare_deck (test.TestGame)
Test preparing the deck for dealing.
----------------------------------------------------------------------
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: type object 'Deck' has no attribute 'deck'

======================================================================
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
TypeError: Poker.__init__() takes 0 positional arguments but 1 was given

======================================================================
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
TypeError: Poker.__init__() takes 0 positional arguments but 1 was given

----------------------------------------------------------------------
Ran 15 tests in 0.166s

FAILED (errors=12)

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

Тихомир обнови решението на 15.11.2022 15:27 (преди около 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):
+ self.deck = []
+ if face_filter == None:
+ for suit in ['clubs', 'diamonds', 'hearts', 'spades']:
+ for face in ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', ]:
+ self.deck.append(Card(suit, face))
+ else:
+ for suit in ['clubs', 'diamonds', 'hearts', 'spades']:
+ for face in face_filter:
+ self.deck.append(Card(suit, face))
+
+ def cut(self):
+ cards_wanted_to_draw = []
+ cards_wanted_to_draw.append(self.deck.pop())
+ number_of_drawed_cards = len(cards_wanted_to_draw)
+ self.deck.append(self.deck.pop(self.deck.index(number_of_drawed_cards)))
+
+ def shuffle(self):
+ random.shuffle(self.deck)
+
+ def get_cards(self):
+ return self.deck
+
+
+class Player:
+
+ def get_cards():

get_cards е методът, който ще използваме, за да вземем картите, които вече си инстанцирал. Това не е метод за инстанциране на карти. Класът ти трябва да работи и без да извиквам този метод.

+ player_hand = []
+ for card in Deck.deck.deal():
+ player_hand.append()
+ return player_hand
+
+
+class Game:
+
+ def __init__(self, number_of_players, dealing_direction, dealing_instructions):
+ self.number_of_players = number_of_players
+ self.dealing_direction = dealing_direction
+ self.dealing_instructions = dealing_instructions
+
+ def get_players(self):
+ self.num_players = self.number_of_players
+ for self.player in range(self.num_players):
+ self.list_of_players.append(self.player)
+ return self.list_of_players
+
+ def prepare_deck(self):
+ Deck.deck.append(Player.get_cards())
+ Deck.deck.shuffle()
+ Deck.deck.cut()
+
+
+class Belot(Game):
+
+ def __init__(self):
+ Game(4, 'ltr', (2, 3, 3))
+
+
+class Poker(Game):
+
+ def __init__():
+ Game(9, 'rtl', (1, 1, 1, 1, 1))