현재 블랙 잭 게임을하고 있으며 현재 구조화되어 있으므로 Card 객체 목록 인 Hand 클래스가 있으며 특정 클래스를 참조하려고합니다. 손에 카드.'Hand'객체가 인덱싱을 지원하지 않습니다.
def get_move(self):
if self.balance > self.bet and not self.isSplit:
if self.hand[0].point == self.hand[1].point:
세 번째 줄에 문제가 발생합니다. 다음과 같은 오류가 나타납니다.
Traceback (most recent call last):
File "driver.py", line 126, in <module>
player.get_move()
File "/home/ubuntu/workspace/finalproject/human_player.py", line 29, in get_move
if self.hand[0].point == self.hand[1].point:
TypeError: 'Hand' object does not support indexing
왜 손을 통해 내 색인을 보내지 않습니까? 여기 내 손 클래스에 생성자는 다음과 같습니다
class Hand:
def __init__(self):
self.hand = []
편집 :
# creating the dealer for the game
dealer_hand = hand.Hand()
dan_the_dealer = dealer.Dealer(dealer_hand)
# for however many players you start with, add each new player to an array of players
for i in range(num_players):
player_name = input("\nWhat is Player %i's name?\n" % (i+1))
new_hand = hand.Hand()
new_player = human_player.HumanPlayer(player_name, starting_balance, 0, new_hand)
players.append(new_player)
어디에서나'Hand' 객체에 대해'hand'를 재정의하지 않습니까? – Iluvatar
그 에러 메시지는'self.hand'가리스트가 아니라'Hand' 객체라는 것을 나타냅니다. 당신이 보여준 코드에서 그 일이 일어나지는 않을 것입니다. 따라서 문제는 보여주지 않는 코드에 있습니다. 버그가 포함 된 코드가 표시되지 않으므로 아무도 도움을 줄 수 없습니다. –
나는 그렇게 믿지 않는다. 내가 그 표식을 찾는다면 그 표정은 어떻게 될 것입니까? – macschmidt33