2012-01-16 20 views
1
function negamax(node, depth, α, β, color) 
    if node is a terminal node or depth = 0 
     return color * the heuristic value of node 
    else 
     foreach child of node 
      val := -negamax(child, depth-1, -β, -α, -color) 
      {the following if statement constitutes alpha-beta pruning} 
      if val≥β 
       return val 
      if val≥α 
       α:=val 
     return α 

所以,如果上面是(從維基百科複製)我negamax代碼,它被稱爲如下:Negamax總是應該返回一個正值?

negamax(origin, depth, -inf, +inf, 1) 

然後,將這個函數總是返回正值,無論我們稱之爲深度功能與。這是假設啓發式價值本身總是正面的。

回答

0

是的,如果葉子節點的評價分數是正值,則negamax將返回正值。這就是顏色值乘法的成就,它確保瞭如果存在奇數個遞歸negamax調用,總會有反向否定來反轉最終的否定。這是因爲在遞歸調用次數爲奇數時,顏色始終爲-1。如果存在偶數次遞歸調用,則所有的否定將被抵消,並且顏色將爲1,這將使返回值不受影響。

請注意,如果您使用顏色== -1調用negamax(這是另一方輪流移動),您必須否定該調用才能獲得正確的值。那就是:

-negamax(origin, depth, -inf, +inf, -1) 
相關問題