当前位置: 代码迷 >> J2SE >> 懂α-β剪枝算法的请进!该如何解决
  详细解决方案

懂α-β剪枝算法的请进!该如何解决

热度:27   发布时间:2016-04-24 01:12:27.0
懂α-β剪枝算法的请进!
研究了好一阵子,最后也只能写成这样、
深度是偶数的时候才能得出最好的值,深度是奇数的最后出来都是最差的值。
搞不定了、
Java code
    // 极小值极大值搜索函数    static int MinMaxSearch(int depth, int alpha, int beta) {         int i, genCount, value, bestValue;        int[] allMoves = new int[MAX_GEN_MOVES];        int eatCount;        int[] eatTable = new int[2]; // 还原局面时用        // 如果搜索到指定深度,则返回局面评估值        if (depth == 0) {            return evaluatePosition();        }        // 初始化最佳值        bestValue = -INFINITY_VALUE; // 负无穷        genCount = generateAllMoves(allMoves);        for (i = 0; i < genCount; i++) {            eatCount = makeOneMove(allMoves[i], eatTable); // 走棋            theDepth++;            value = -MinMaxSearch(depth - 1, -beta, -alpha); // 递归            undoOneMove(allMoves[i], eatCount - 1, eatTable); // 还原            theDepth--;            if (value >= beta) {                return value;            }            if (value > bestValue) {                bestValue = value;                if (depth == search_depth) { // 如果是根节点 保存最佳走法                    bestMove = allMoves[i];                }                if (value > alpha) {                    alpha = value;                }            }        }        // 如果是杀棋,就根据距杀棋的步数给出评价        if (currentPlayer == BLACK) { // 如果是黑方            if (bestValue == INFINITY_VALUE) {                return INFINITY_VALUE - theDepth;            }        } else { // 是白方            if (bestValue == -INFINITY_VALUE) {                return theDepth - INFINITY_VALUE;            }        }        return bestValue; // 返回找到的最佳局面评分    }


------解决方案--------------------
α-β 恍惚的记得在初中几何的时候见过 阿拉法 肥塔 还有一个叫 嘎麻
  相关解决方案