我认为这是一个全局或局部错误,但我不明白
def who_wins_when_player_3(player):
if player == 3:
amount_triangles = np.count_nonzero(board == 3)
if amount_triangles == 3 or 5 or 7:
player = 2
else:
player = 1
在这里它不起作用:
# vertical win check
for col in range(BOARD_COLS):
if board[0][col] == player and board[1][col] == player and board[2][col] == player or board[3][col] == player and board[1][col] == player and board[2][col] == player:
who_wins_when_player_3()
print(f"Player {player} wins")
return True
它在这里工作:
# vertical win check
for col in range(BOARD_COLS):
if board[0][col] == player and board[1][col] == player and board[2][col] == player or board[3][col] == player and board[1][col] == player and board[2][col] == player:
if player == 3:
amount_triangles = np.count_nonzero(board == 3)
if amount_triangles == 3 or 5 or 7:
player = 2
else:
player = 1
print(f"Player {player} wins")
return True
错误在哪里
致意
除非
return
指定值,否则在函数内赋值不会起任何作用。尝试此版本的函数,其中返回player
的中奖值:然后让调用者将其分配给其自身范围内的
player
:这段代码可能还有其他问题,但希望至少能澄清函数返回值的工作原理
相关问题 更多 >
编程相关推荐