[英]Return move as well by changing this pseudocode
有沒有辦法重寫這個修改過的偽代碼,以便它返回一個移動和一個分數? 在這里找到。 這是Alpha-Beta
算法,它是Minimax
算法的優化版本,兩者都用於在完美信息游戲中找到最佳移動,如Tic-Tac-Toe
。
function alphabeta(node, α, β, maximizingPlayer)
if node is a terminal node
return the value of node
if maximizingPlayer
v = -∞
for each child of node
v = max(v, alphabeta(child, α, β, FALSE))
α = max(α, v)
if β ≤ α
break
return v
else
v = ∞
for each child of node
v = min(v, alphabeta(child, α, β, TRUE))
β = min(β, v)
if β ≤ α
break
return v
最小化實際上與最大化相似,所以只做一部分:
function alphabeta(node, α, β, maximizingPlayer)
if node is a terminal node
return { value: value of node, node : node}
if maximizingPlayer
v = -∞
bestNode = None
for each child of node
localMax = alphabeta(child, α, β, FALSE)
if localMax.value > v
v = localMax.value
bestNode = localMax.node
α = max(α, v)
if β ≤ α
break
return {value : v, node: bestNode}
只是最大化部分b / c兩者都是相似的
function alphabeta(node, a, b, maximizingPlayer)
if node is a terminal node
return valueOfNode, None
if maximizingPlayer
v = -∞
for each move in node.possible_moves()
child = play(move, TRUE) #True / False respresents if it should make an "x" or an "o" on the board
temp_max, _ = alphabeta(child, a, b, FALSE) # "_" means disregard the value
if temp_max > v:
v = temp_max
best_move = move
a = max(a, v)
if b <= a:
break
return v, best_move
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.