beta in Connect Four
My minimax algorithm is returning very bad move choice after I apply alpha-beta pruning to the game of Connect Four.
def get_next_move(board, player, depth, alpha, beta) :
score = get_score(board, depth)
if score is not None :
return score, board
if depth == 0 :
return 0, board
if player is AI :
best = LOSS
best_move = None
possible_moves = get_possible_moves(board, player)
for 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)
for 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 I try to implement alpha-beta.
链接地址: http://www.djcxy.com/p/56364.html上一篇: 游戏AI中的机器学习
下一篇: Connect Four中的测试版