1

来源:互联网 发布:止水螺栓算法 编辑:程序博客网 时间:2024/06/02 02:04
int MiniMmax(node,depth,isMaxPlayer) {if (depth == 0) {return Evaluate(node);}int score = isMaxPlayer ? -INFINITY : INFINITY;for_each(node的子节点child_node) {int value = MiniMax(child_node, depth - 1, !isMaxPlayer);if (isMaxPlayer)score = max(score, value);elsescore = min(score, value);}}

int NegaMax(node, depth, color) {if (depth == 0) {return color*Evaluate(node);}int score = -INFINITY;for_each(node的子节点child_node) {int value = -NegaMax(child_node, depth - 1, -color);score = max(score, value);}}

int MiniMax_AlphaBeta(node, depth, α, β, isMaxPlayer){if (depth == 0){return Evaluate(node);}if (isMaxPlayer) {for_each(node的子节点child_node) {int value = MiniMax_AlphaBeta(child_node, depth - 1, α, β, FALSE);α = max(α, value);if (α >= β)/*β剪枝*/break;}return α;}else {for_each(node的子节点child_node) {int value = MiniMax_AlphaBeta(child_node, depth - 1, α, β, TRUE);β = min(β, value);if (α >= β)/*α剪枝*/break;}return β;}}

int FeEvaluator::Evaluate(GameState& state, int max_player_id) {int min = GetPeerPlayer(max_player_id);int aOne, aTwo, aThree, bOne, bTwo, bThree;CountPlayerChess(state, max_playe_id, aOne, aTwo, aThree);CountPlayerChess(state, min, bOne, bTwo, bThree);if (aThree > 0) {return INFINITY;}if (bThree > 0){return -INFINITY;}return (aTwo - bTwo)*DOUBLE_WEIGHT + (aOne - bOne);}

0 0
原创粉丝点击