问题描述
这是井字游戏的alpha-beta修剪算法的实现,问题是它没有给我最好的结果。
def alpha_beta_policy(board,p):
def recurse(b,alpha,beta,player):
if is_game_over(b) != False:
return (utility(b),'none')
if player == 1:
value = (float('inf') * -1,(-100,-100))
for i in range(len(legal_moves(b))):
recursion = (recurse(make_move(b,player,legal_moves(b)[i],False),player*-1)[0],legal_moves(b)[i])
value = max(value,recursion)
alpha = max(alpha,value[0])
if alpha >= beta:
break # cut-off
return value
elif player == -1:
value = (float('inf'),(100,100))
for i in range(len(legal_moves(b))):
recursion = (recurse(make_move(b,legal_moves(b)[i])
value = min(value,recursion)
beta = min(beta,value[0])
if beta <= alpha:
break # cut-off
return value
else:
raise Error('ERROR: Invalid player selection.')
value,action = recurse(board,float('inf')*-1,float('inf'),p)
print(f'alpha-beta says action = {action} and value = {value}')
return action
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)