代码拉取完成,页面将自动刷新
function [ best_val, best_pos ] = minimax_alpha_beta( Board, depth, player, alpha, beta,is_max)
% Minimax helper function: Return the minimax value of a particular board,
% given a particular depth to estimate to
%
%best_val = 0;
%best_pos = randi(7);
%[ best_val, best_pos ] = minimax( Board, depth, player );
if(is_terminal(Board,depth))
best_val = eval_game(Board, depth, player);
return;
end
if(is_max)% jogador
best_val = -Inf;
for j=1:7
[new_Board, valid] = do_move( Board, j, player);
if valid == 1
v = minimax_alpha_beta(new_Board, depth-1, player, alpha, beta,false);
if(v > best_val)
best_val = v;
best_pos = j;
end
alpha = max(alpha,best_val);
if(beta <= alpha)
return;
end
end
end
else % oponente
best_val = Inf;
for j=1:7
[new_Board, valid] = do_move( Board, j, opposite_player(player));
if valid == 1
v = minimax_alpha_beta(new_Board, depth-1, player, alpha, beta,true);
if(v < best_val)
best_val = v;
best_pos = j;
end
beta = min(beta,best_val);
if(beta <= alpha)
return;
end
end
end
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。