Artificial Intelligence Minimax and Alpha Beta Pruning code

function alphabeta(node, depth, α, β, Player)        

    if depth = 0 or node is a terminal node

        return the heuristic value of node

    if Player = MaxPlayer

        for each child of node

            α := max(α, alphabeta(child, depth-1, α, β, not(Player) ))    

            if β ≤ α

                break                             (* Beta cut-off *)

        return α

    else

        for each child of node

            β := min(β, alphabeta(child, depth-1, α, β, not(Player) ))    

            if β ≤ α

                break                             (* Alpha cut-off *)

        return β

(* Initial call *)

alphabeta(origin, depth, -infinity, +infinity, MaxPlayer)

posted @ 2012-05-18 18:37  SolidMango  阅读(345)  评论(0编辑  收藏  举报