Connect Four中的测试版
在我将Alpha-beta修剪应用于Connect Four的游戏后,我的minimax算法返回了非常糟糕的移动选择。
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
一切工作正常,直到我尝试实施alpha-beta。
链接地址: http://www.djcxy.com/p/56363.html上一篇: beta in Connect Four
下一篇: beta pruning remove randomness in my solution with minimax?