-1

I'm evaluating chess positions, the implementation isn't really relevant. I've inserted print checks to see how many paths I'm able to prune, but nothing is printed, meaning I don't really prune anything.

I've understood the algorithm and followed the pseudo-code to the letter. Anyone has any idea on what's going wrong?

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
desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

What is your pseudo code ? The one I found gives a little diferent code:

As I do not have your full code, I cannot run it:

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

A full working simple chess program can be found here: https://andreasstckl.medium.com/writing-a-chess-program-in-one-day-30daff4610ec

Malo
  • 1,233
  • 1
  • 8
  • 25