Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python connect 4播放函数_Python_Python 3.x_Connect Four - Fatal编程技术网

Python connect 4播放函数

Python connect 4播放函数,python,python-3.x,connect-four,Python,Python 3.x,Connect Four,我正在为一个类制作一个connect4游戏,我的play函数遇到了一个错误,我很难弄清楚 def play(grid,column,checker): counter = 0 for x in grid[0]: counter += 1 print(counter) if counter > column-1 : for row in reversed(grid): if row[column

我正在为一个类制作一个connect4游戏,我的play函数遇到了一个错误,我很难弄清楚

def play(grid,column,checker):
    
    counter = 0
    for x in grid[0]:
        counter += 1
    print(counter)
    if counter > column-1 :
        for row in reversed(grid):
            if row[column-1] == "empty":
                row[column-1] = checker
                print(True)
                return True,grid,checker
    else:
        print(False)
        return False  , grid , checker
问题发生在第9行(如果行[column-1]=“empty”),我一直得到typeError“int”opject不可下标。 grid是从其他函数返回的全局变量。
谢谢你的帮助

这里的问题实际上是不同的函数返回的
网格
。您一定犯了一些错误,这导致不同的函数返回形式为
[1,6,3,8,3]
,而您的
play
函数采用形式为
[[1,5,6,2,10],[1,5,6,2,10],[1,5,6,2,10],[1,5,6,2,10]]

它的意思是
是一个
int
。也许你想把
网格
作为列表传递,而你只是传递了一个列表,所以你的行(你希望它是一个列表)是一个整数。它试图访问行[column-1],这是整数无法访问的,您会收到错误消息谢谢!我编辑了我的网格函数,试图返回多个值,这些值在我没有意识到的情况下把一切都搞糟了。@808值没问题!