1 Star 0 Fork 0

sqy/connect-4-artificial-intelligence

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
minimax_alpha_beta.m 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
Ricardo Aguiar 提交于 2018-02-13 00:49 . Add files via upload
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqyyyyy/connect-4-artificial-intelligence.git
git@gitee.com:sqyyyyy/connect-4-artificial-intelligence.git
sqyyyyy
connect-4-artificial-intelligence
connect-4-artificial-intelligence
master

搜索帮助