Python 2.7 我的分数列表没有更新。Python(Tic-Tac-Toe)

Python 2.7 我的分数列表没有更新。Python(Tic-Tac-Toe),python-2.7,list,Python 2.7,List,下面是发生的情况。 麦丘动议 创建分数列表并将其作为参数提供给mc_update_score mc_update_score执行所有计算并更新列表(我在mc_update_score函数的末尾通过打印进行了检查)。 但是,在mc_move的下一次迭代中,分数列表被设置为初始值-全零。尽管它应该是包含mc_update_score值的列表。 我错过了什么 def mc_update_scores(scores, board, player): print "scores at the b

下面是发生的情况。 麦丘动议 创建分数列表并将其作为参数提供给mc_update_score

mc_update_score执行所有计算并更新列表(我在mc_update_score函数的末尾通过打印进行了检查)。 但是,在mc_move的下一次迭代中,分数列表被设置为初始值-全零。尽管它应该是包含mc_update_score值的列表。 我错过了什么

def mc_update_scores(scores, board, player):

    print "scores at the begining of the function is"
    print scores
    for i in empty_list_score:
       # iterate through all the squares of the board
        col = i[1]
        row = i[0]
        if board.check_win() == provided.DRAW:
            scores[row][col] += 0
            #print score[row][col]
        elif board.check_win() == provided.PLAYERX:
            if board.square(row,col) == provided.PLAYERX:
                scores[row][col] += SCORE_CURRENT
            elif board.square(row,col) == provided.PLAYERO: 
                scores[row][col] -= SCORE_OTHER
            else:
                scores[row][col] += 0        
       # print score[row][col]


        elif board.check_win() == provided.PLAYERO:
            if board.square(row,col) == provided.PLAYERO:
                scores[row][col] += SCORE_CURRENT
            elif board.square(row,col) == provided.PLAYERX: 
                scores[row][col] -= SCORE_OTHER
            else:
                scores[row][col] += 0
    print
    print "Scores at the end"
    print scores 



def mc_move(board, player, trials):

    global empty_list_score

    empty_list_score =board.get_empty_squares()

    scores = [[0  for col in range(board.get_dim())]for row in range(board.get_dim())] # create score board
    # Here we create the scores list just once at function call and from here on
    # it only gets updated. Like each element is getting changed by +1 or - 1.
    # i do not see any spot where the entire list is being created again or 
    #emptied = e.g. is set to all zeros.
    num = 0


    while num < trials:
        board_c = board.clone() # create new board for every iteration
        mc_trial(board_c, player) # play a full game for every iteration
        mc_update_scores(scores, board_c, player)  # update score for every 
           #iteration after the game is played. 

        num +=1
def mc_更新_分数(分数、棋盘、玩家):
打印“函数开头的分数为”
打印分数
对于空列表中的i,分数:
#遍历棋盘的所有方块
col=i[1]
行=i[0]
如果board.check_win()==提供的.DRAW:
分数[行][列]+=0
#打印分数[行][列]
elif board.check_win()==provided.PLAYERX:
如果board.square(行、列)=提供的.PLAYERX:
分数[行][列]+=当前分数
elif board.square(行、列)=提供。PLAYERO:
分数[行][列]-=其他分数
其他:
分数[行][列]+=0
#打印分数[行][列]
elif board.check_win()==provided.PLAYERO:
如果board.square(行、列)=提供的.PLAYERO:
分数[行][列]+=当前分数
elif board.square(行、列)=提供的.PLAYERX:
分数[行][列]-=其他分数
其他:
分数[行][列]+=0
打印
打印“结尾处的分数”
打印分数
def mc_移动(棋盘、玩家、测试):
全局空列表分数
空列表得分=板。获取空方块()
分数=[[0表示范围内的列(board.get_dim())]表示范围内的行(board.get_dim())]#创建分数板
#在这里,我们仅在函数调用时创建一次分数列表,从这里开始
#它只会被更新,就像每个元素都会被+1或-1改变一样。
#我看不到任何地方正在重新创建或删除整个列表
#清空=例如,设置为全零。
num=0
而num<试验:
board_c=board.clone()#为每次迭代创建新板
mc#U试用版(棋盘游戏,玩家)#在每次迭代中玩完整的游戏
mc#U更新#U分数(分数、棋盘、球员)#更新每个人的分数
#游戏结束后进行迭代。
num+=1

您正在执行的是增量为零的
+=0
。您是否打算编写
+=1
?有不同的情况。正如您所看到的,有些do+1,有些-1,有些保持原样+0。可能没有意义)但就我所见,这并不影响列表的不当行为。
mc_-trial
call
mc_-move
?在我看来,
分数
没有明显的理由被重置为全零,但我们没有所有的代码(因此我们无法运行您的代码自行调试)。递归将是看到更多零分的一个原因。你能做一个大概吗?@Blckknght这里是完整可执行代码的链接。mc_试用版不会返回任何内容。它所做的只是更新电路板,然后在mc_移动的下一步中使用。至少应该是这样的)从代码来看,我唯一看到的是
NTRIALS
1
,因此您的
while
循环可能只运行一次。这段代码还没有“完成”,因为我无法下载它并在自己的系统上运行它(它依赖于各种其他模块,我对此一无所知),所以我仍然只是在猜测发生了什么。您正在做的
+=0
,增量为零。你的意思是写
+=1
?有不同的情况。正如您所看到的,一些do+1、一些-1和一些保持原样+0。可能没有任何意义),但就我所见,它不会影响列表的不当行为。
mcu-trial
call
mcu-move
?在我看来,
分数
没有明显的理由被重置为全零,但我们没有所有的代码(因此我们无法运行您的代码自行调试)。递归将是看到更多零分的一个原因。你能做一个大概吗?@Blckknght这里是完整可执行代码的链接。mc_试用版不会返回任何内容。它所做的只是更新电路板,然后在mc_移动的下一步中使用。至少应该是这样的)从代码来看,我唯一看到的是
NTRIALS
1
,因此您的
while
循环可能只运行一次。这段代码仍然不“完整”,因为我无法下载它并在自己的系统上运行(它依赖于各种其他模块,我对此一无所知),所以我仍然只是在猜测发生了什么。