connect 4在python AI中,列表索引必须是整数或切片,而不是NoneType

connect 4在python AI中,列表索引必须是整数或切片,而不是NoneType,python,artificial-intelligence,heuristics,alpha-beta-pruning,connect-four,Python,Artificial Intelligence,Heuristics,Alpha Beta Pruning,Connect Four,嗨,我在大学里用python学习AI,我的Connect 4游戏代码有问题。 我使用了minimax和alphabetaprunning算法 我的程序运行了,但当轮到人工操作时,当我想在已经有3个芯片的列中添加一个芯片时,我得到一个错误:“TypeError:列表索引必须是整数或片,而不是非非类型” 错误来自我的函数make_move(在函数的第一行): 在getNext函数中调用make_move: def make_move(s, r, c): s[0][r][c] = s[2]

嗨,我在大学里用python学习AI,我的Connect 4游戏代码有问题。 我使用了minimax和alphabetaprunning算法

我的程序运行了,但当轮到人工操作时,当我想在已经有3个芯片的列中添加一个芯片时,我得到一个错误:“TypeError:列表索引必须是整数或片,而不是非非类型”

错误来自我的函数make_move(在函数的第一行):

在getNext函数中调用make_move:

def make_move(s, r, c):
    s[0][r][c] = s[2]  # marks the board =>the line of the error
    s[3] -= 1  # one less empty cell
    s[2] = COMPUTER + HUMAN - s[2]  # switches turns
    if winning_move(s, HUMAN):
        s[1] = LOSS
        return
    if winning_move(s, COMPUTER):
        s[1] = VIC
        return
    else:
        # my heuristic
        threesH = check_threes(s, HUMAN) * 1000
        twosH = check_twos(s, HUMAN) * 10
        threesC = check_threes(s, COMPUTER) * 1000
        twosC = check_twos(s, COMPUTER) * 10
        scores = threesH + twosH - threesC - twosC
        s[1] += scores
    if s[3] == 0:
        s[1] = TIE
def getNext(s): 
    valid_locations = []
    for col in range(COLUMN_COUNT):
        if is_valid_location(s, col):
            tmp = copy.deepcopy(s)
            r=get_next_open_row(s,col)
            make_move(tmp, r, col)
            valid_locations += [tmp]
    return valid_locations
我想可能函数get\u next\u open\u row为r返回了一个错误的值

def get_next_open_row(s, col):
    for r in range(ROW_COUNT-1, 0, -1):
        if s[0][r][col] == 0:
            return r
游戏状态由4项列表表示:

  • 游戏板-整数矩阵(列表列表)。空单元格=0, 公司的细胞=计算机,人的细胞=人
  • 状态的启发式值
  • 轮到谁了:人类还是计算机
  • 空单元格数

  • 感谢您的帮助和时间:-)

    在函数开始时打印(s)、打印(r)、打印(c),其中一个可能会显示“无”。这就是为什么你会遇到这个错误。非常感谢你。现在它工作了,我在@JustinOberle发现了我的错误