【问题标题】:Alpha-Beta pruning algorithm in python not pruningpython中的Alpha-Beta修剪算法不修剪
【发布时间】:2020-12-20 15:10:19
【问题描述】:

我正在评估国际象棋位置,实施并不真正相关。我已插入打印检查以查看我可以修剪多少条路径,但没有打印任何内容,这意味着我并没有真正修剪任何东西。

我已经理解了算法,并且完全按照伪代码进行了操作。有人知道出了什么问题吗?

def alphabeta(self,node,depth,white, alpha,beta):
    ch = Chessgen()
    if(depth == 0 or self.is_end(node)):
        return self.stockfish_evaluation(node.board)


    if (white):
        value = Cp(-10000)
        for child in ch.chessgen(node):
            value = max(value, self.alphabeta(child,depth-1,False, alpha,beta))
            alpha = max(alpha, value)
            if (alpha >= beta):
                print("Pruned white")
                break
        return value

    else:
        value = Cp(10000)
        for child in ch.chessgen(node):
            value = min(value, self.alphabeta(child,depth-1,True, alpha,beta))
            beta = min(beta,value)
            if(beta <= alpha):
                print("Pruned black")
                break
        return value

【问题讨论】:

    标签: python artificial-intelligence chess pruning


    【解决方案1】:

    你的伪代码是什么? 我发现的那个给出了一些不同的代码:

    由于我没有你的完整代码,我无法运行它:

    def alphabeta(self,node,depth,white, alpha,beta):
           ch = Chessgen() ### can you do the init somewhere else to speed up the code ?
           if(depth == 0 or self.is_end(node)):
               return self.stockfish_evaluation(node.board)
    
    
           if (white):
               value = Cp(-10000)
               for child in ch.chessgen(node):
                   value = max(value, self.alphabeta(child,depth-1,False, alpha,beta))
                   if (value >= beta):
                       print("Pruned white")
                       return value
                   alpha = max(alpha, value)
               return value
    
           else:
               value = Cp(10000)
               for child in ch.chessgen(node):
                   value = min(value, self.alphabeta(child,depth-1,True, alpha,beta))
                   if(value <= alpha):
                       print("Pruned black")
                       return value
                   beta = min(beta,value)
               return value
    

    可以在此处找到完整的工作简单国际象棋程序: https://andreasstckl.medium.com/writing-a-chess-program-in-one-day-30daff4610ec

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多