Alpha-Beta搜索截断我的主要变体

时间:2016-06-13 02:15:35

标签: algorithm chess minimax alpha-beta-pruning

我已经实现了alpha-beta搜索,将其结果添加到转置表中。然后,我从转置表中提取主要变体。

这似乎可以在浅层进行分析。但是,当我要求在7层深度进行分析时,我得到了这个:

7 [+1.00] 1.b1c3 a7a6 2.g1f3 a6a5 3.a6a5 

最后,重复一次行动。由于修剪,这个最后的举动被放在桌子上,但它甚至不是白色的合法举措。显然,印刷的层数不到7层。

这是我的alpha-beta搜索代码中的误解吗?

int ab_max(board *b, int alpha, int beta, int ply) {
    if (ply == 0) return evaluate(b);
    int num_children;
    move chosen_move = no_move;
    move *moves = board_moves(b, &num_children);
    assert(num_children > 0);
    for (int i = 0; i < num_children; i++) {
        apply(b, moves[i]);
        int score = ab_min(b, alpha, beta, ply - 1);
        if (score >= beta) {
            tt_put(b, (evaluation){moves[i], score, at_least, ply});
            unapply(b, moves[i]);
            free(moves);
            return beta; // fail-hard
        }
        if (score > alpha) {
            alpha = score;
            chosen_move = moves[i];
        }
        unapply(b, moves[i]);
    }
    tt_put(b, (evaluation){chosen_move, alpha, exact, ply});
    free(moves);
    return alpha;
}

int ab_min(board *b, int alpha, int beta, int ply) {
    if (ply == 0) return evaluate(b);
    int num_children;
    move chosen_move = no_move;
    move *moves = board_moves(b, &num_children);
    assert(num_children > 0);
    for (int i = 0; i < num_children; i++) {
        apply(b, moves[i]);
        int score = ab_max(b, alpha, beta, ply - 1);
        if (score <= alpha) {
            tt_put(b, (evaluation){moves[i], score, at_most, ply});
            unapply(b, moves[i]);
            free(moves);
            return alpha; // fail-hard
        }
        if (score < beta) {
            beta = score;
            chosen_move = moves[i];
        }
        unapply(b, moves[i]);
    }
    tt_put(b, (evaluation){chosen_move, beta, exact, ply});
    free(moves);
    return beta;
}

这是我的评估打印功能的有趣部分:

do {
        if (!b->black_to_move) printf("%d.", moveno++);
        char move[6];
        printf("%s ", move_to_string(eval->best, move));
        apply(b, eval->best);
        eval = tt_get(b);
    } while (eval != NULL && depth-- > 0);

我的主要变体中的任何动作都不应该被修剪,对吗?

1 个答案:

答案 0 :(得分:0)

我正在回答我自己的问题,为未来的国际象棋作家留下几个小时的悲伤。

有一个微不足道的错误,当发生截止时,我不太适应这一举动。

然而,这里描述了更有趣的问题:Chess: Extracting the principal variation from the transposition table

相关问题