2013-11-27 4 views
0
def take_turn(Nplayers, hands, player, pile, turn): 
    while finished(hands) is not True: 
     pile.append(hands[player][0]) # this line 
     hands[player].pop(0) 
     while pile[-1] <= 10: 
      print(turn, ':', '\nPile:', pile, '\nHands\n', '\n'.join(map(str, hands)), '\n') 
      check_players(Nplayers, hands, player, pile, turn) 
      turn += 1 
      player = (player + 1) % Nplayers 
      if len(hands[player]) == 0: 
       hands.pop(player) 
       Nplayers -= 1 
       player = player % Nplayers 
      pile.append(hands[player][0]) 
      hands[player].pop(0) 
      if table[-1] > 10: 
      break 
     penalty_card(Nplayers, hands, player, pile, turn) 
    return turn 

줄에 표시된 내용은 내 프로그램에서 제목에 표시된 오류를 반환합니다. 플레이어를 초기에 0으로 설정 했으므로 다음과 같이해야합니다. 아무런 문제가 없습니까?TypeError : 목록 색인은 목록이 아닌 정수 여야합니다.

편집 : 손이 목록의 목록입니다, 플레이어는 정수

+0

'take_turn' 기능을 호출하는 추적 코드와 코드를 표시 할 수 있습니까? – falsetru

+1

'손'과 '플레이어'는 무엇입니까? – karthikr

+0

손이 목록의 목록입니다, 플레이어는 정수입니다, 코드는 수백 줄입니다 ... – harryjmm

답변

0

입니다 그것은 작동하는 코드 샘플을 제공 한 경우에 도움을 훨씬 더 쉽게 될 것입니다. 부작용이있는 여러 기능이있는 것 같습니다. 아마도 문제를 담고 실행 가능한 데모를 만들기 위해 다음과 같은 몇 가지 최소 모의 (mocks)와 샘플 호출을 포함 할 수있을 것입니다.

def finished(hands): 
     if len(hands) == 0: 
      return True 
     return False 


def check_players(*args, **kwargs): 
    pass 


def penalty_card(*args, **kwargs): 
    pass 


table = [9] 


def take_turn(Nplayers, hands, player, pile, turn): 
    while finished(hands) is not True: 
     pile.append(hands[player][0]) # this line 
     hands[player].pop(0) 
     while pile[-1] <= 10: 
      print(turn, ':', '\nPile:', pile, '\nHands\n', '\n'.join(map(str, hands)), '\n') 
      check_players(Nplayers, hands, player, pile, turn) 
      turn += 1 
      player = (player + 1) % Nplayers 
      if len(hands[player]) == 0: 
       hands.pop(player) 
       Nplayers -= 1 
       player = player % Nplayers 
      pile.append(hands[player][0]) 
      hands[player].pop(0) 
      if table[-1] > 10: 
       break 
     penalty_card(Nplayers, hands, player, pile, turn) 
    return turn 


take_turn(Nplayers=1, hands=[[1,1,1], [1,1], [1]], player=0, pile=[5, 5], turn=3) 
관련 문제