artificial intelligence - Alpha-beta in Connect Four -


my minimax algorithm returning bad move choice after apply alpha-beta pruning game of connect four.

def get_next_move(board, player, depth, alpha, beta) :     score = get_score(board, depth)     if score not none :         return score, board     if depth == 0 :         return 0, board      if player ai :         best = loss         best_move = none         possible_moves = get_possible_moves(board, player)          move in possible_moves :             move_score = get_next_move(move, player, depth-1, alpha, beta)[0]             if move_score >= best :                 best = move_score                 best_move = move                 alpha = max(alpha, best)             if alpha >= beta :                 break         return best, best_move     else :         best = win         best_move = none         possible_moves = get_possible_moves(board, player)          move in possible_moves :             move_score = get_next_move(move, ai, depth-1, alpha, beta)[0]             if move_score <= best :                 best = move_score                 best_move = move                 beta = min(best, beta)              if beta <= alpha :                 break         return best, best_move 

everything works fine until try implement alpha-beta.


Comments