Alpha beta algorithm

Hello!

I implemented a minimax algorithm with alpha beta cropping. To get the best move, I call the alpha-beta algorithm using the `rootAlphaBeta` function. However, I noticed some very strange behavior. When I call the rootAlphaBeta function with layer 4, it makes about 20,000 calls, but when I call the `alphaBeta` function directly, it only makes 2,000 calls or so. It seems I can not find the problem, since the number of calls should be the same. The movement that both algorithms ultimately find is the same (I think that at least the motion estimation is the same, I don’t know how alphaBeta moves when I call it directly without rootAlphaBeta).

def alphaBeta(self, board, rules, alpha, beta, ply, player):
        """ Implements a minimax algorithm with alpha-beta pruning. """
        if ply == 0:
            return self.positionEvaluation(board, rules, player)

        move_list = board.generateMoves(rules, player)
        for move in move_list:
            board.makeMove(move, player)
            current_eval = -self.alphaBeta(board, rules, -beta, -alpha, ply - 1, board.getOtherPlayer(player))
            board.unmakeMove(move, player)

            if current_eval >= beta:
                return beta

            if current_eval > alpha:
                alpha = current_eval

        return alpha

def rootAlphaBeta(self, board, rules, ply, player):
        """ Makes a call to the alphaBeta function. Returns the optimal move for a player at given ply. """
        best_move = None
        max_eval = float('-infinity')

        move_list = board.generateMoves(rules, player)
        for move in move_list:
            board.makeMove(move, player)
            current_eval = -self.alphaBeta(board, rules, float('-infinity'), float('infinity'), ply - 1, board.getOtherPlayer(player))
            board.unmakeMove(move, player)

            if current_eval > max_eval:
                max_eval = current_eval
                best_move = move

        return best_move

Many thanks!

+5
source share
1

rootAlphaBeta alpha. (-inf, inf), , . , , node.

+4

All Articles