无与伦比的Tic Tac Toe Bot出错

时间:2017-10-28 15:26:02

标签: python artificial-intelligence tic-tac-toe

在python中查看Unbeatable tic Tac toe bot的代码,我在类中找到了这两个函数:

def __minimax(self, player):

    if self.won():
        if player:
            return (-1,None)
        else:
            return (+1,None)
    elif self.tied():
        return (0,None)
    elif player:
        best = (-2,None)
        for x,y in self.fields:
            if self.fields[x,y]==self.empty:
                value = self.move(x,y).__minimax(not player)[0]
                if value>best[0]:
                    best = (value,(x,y))
         return best
     else:
         best = (+2,None)
         for x,y in self.fields:
             if self.fields[x,y]==self.empty:
                 value = self.move(x,y).__minimax(not player)[0]
                 if value<best[0]:
                     best = (value,(x,y))
         return best

  def best(self):

      return self.__minimax(True)[1]

使用best__minimax调用True [1]函数的功能如何? True[1]代表什么?

0 个答案:

没有答案