AlphaBeta与TT(MTD-f)

时间:2018-05-24 14:31:54

标签: c++ algorithm chess minimax alpha-beta-pruning

我的问题是关于TTalphabeta。在MTD-f的论文(https://people.csail.mit.edu/plaat/mtdf.html)中,alpha beta的实现与我发现的其他文章完全不同(https://homepages.cwi.nl/~paulk/theses/Carolus.pdf

他们之间有什么区别?

我的启发式返回一个int所以没有我没有小数,我应该特别小心吗?

我的实施知道是:

template <class node, class transposition_table>
bound_and_action<node> alpha_beta_with_memory(node& root, depth depth,
        bound alpha, bound beta, transposition_table& table)
{


    auto value_in_hash = table.find(root);

    if (value_in_hash != table.end()
            && value_in_hash->second._depth > depth) { // Transposition table lookup

        auto bound_in_hash = value_in_hash->second;


        if ( bound_in_hash.lower_bound >= beta )
          return { bound_in_hash.lower_bound, root.get_action() };

        if ( bound_in_hash.upper_bound <= alpha )
          return { bound_in_hash.upper_bound, root.get_action() };


        alpha = std::max(alpha, bound_in_hash.lower_bound);
        beta = std::min(beta, bound_in_hash.upper_bound);
    }

    bound_and_action<node> ret;

    if ( depth == 0 || root.is_terminal() ) { // Leaf Node

      ret._bound = root.get_heuristic_value();
      ret._action = root.get_action();

    } else {

         list<node> children;
        root.get_children(children);

        if (root.is_max_node()) {

            ret._bound = INT_MIN;
            bound a = alpha; //Save original alpha

            for (auto child : children) {


                bound_and_action<node> possible_ret = alpha_beta_with_memory(child, depth - 1,
                                                      a, beta, table);

                if (possible_ret._bound == 1000) {
                    return {1000, root.get_action()};
                }

                if (possible_ret._bound > ret._bound ) {
                    ret._bound = possible_ret._bound;
                    ret._action = child.get_action();
                }

                a = std::max(a, ret._bound);

                if ( beta <= ret._bound ) {
                    break;    // beta cut-off
                }

            }

        } else { // if root is a min node.

            ret._bound = INT_MAX;
            bound b = beta; //Save original beta


            for (auto child : children) {


                bound_and_action <node> possible_ret = alpha_beta_with_memory(child, depth - 1,
                                                       alpha, b, table);

                if (possible_ret._bound == 1000) {
                    return {1000, root.get_action()};
                }

                if (possible_ret._bound < ret._bound) {
                    ret._bound = possible_ret._bound;
                    ret._action = child.get_action();
                }

                b = std::min(b, ret._bound);

                if ( ret._bound <= alpha ) {
                    break;    // alpha cut-off
                }

            }
        }
    }

    //
    //  ----- Transposition table storing of bounds.

    hash_struct& hash_value = table[root];

    if (hash_value._depth < depth) {
        // Fail low result implies an upper bound.
        if (ret._bound <= alpha) {
            hash_value.upper_bound = ret._bound;
        }
        // Found an accurate minimax value - will not occur if called with zero window.
        if ( ret._bound > alpha && ret._bound < beta){
          hash_value.lower_bound = ret._bound;
          hash_value.upper_bound = ret._bound;
        }

        // Fail high result implies a lower bound.
        if (ret._bound >= beta ) {
            hash_value.lower_bound = ret._bound;
        }

        hash_value._depth = depth;
        hash_value._action = ret._action;
    }

    return ret;
}

但它没有那么好用。 如果没有使用TT,一切都很好,所以使用它的东西一定是错的。

0 个答案:

没有答案