问题描述
我找到了一个 3 x 3 tic tac toe 游戏的 minimax 代码,我想将其更改为 Alpha-beta minimax,因为我打算创建一个 6 x 6 tic tac toe。
这是来自 this github 的原始代码:
def minimax(state,depth,player):
"""
AI function that choice the best move
:param state: current state of the board
:param depth: node index in the tree (0 <= depth <= 9),but never nine in this case (see iaturn() function)
:param player: an human or a computer
:return: a list with [the best row,best col,best score]
"""
if player == COMP:
best = [-1,-1,-infinity]
else:
best = [-1,+infinity]
if depth == 0 or game_over(state):
score = evaluate(state)
return [-1,score]
for cell in empty_cells(state):
x,y = cell[0],cell[1]
state[x][y] = player
score = minimax(state,depth - 1,-player)
state[x][y] = 0
score[0],score[1] = x,y
if player == COMP:
if score[2] > best[2]:
best = score # max value
else:
if score[2] < best[2]:
best = score # min value
return best
这是我添加 Alpha Beta 的尝试:
def minimax(state,alpha,beta,best score]
"""
if depth == 0 or game_over(state):
score = evaluate(state)
return [-1,score]
if player == COMP:
best = [-1,+infinity]
for cell in empty_cells(state):
x,y
if player == COMP:
if score[2] > best[2]:
best = score # max value
alpha = max(alpha,score[2]) #added alpha
if beta <= alpha:
break
else:
if score[2] < best[2]:
best = score # min value
beta= min(beta,score[2]) #added beta
if beta <= alpha:
break
return best
我是算法的新手,这里的代码模式与我在网上找到的许多模式不同。是否可以进行任何更改以将其转变为 Alpha-beta 修剪极小极大值?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)