АльфаБета с ТТ (MTD-f) - PullRequest
       128

АльфаБета с ТТ (MTD-f)

0 голосов
/ 24 мая 2018

Мой вопрос о TTalphabeta.В статье MTD-f (https://people.csail.mit.edu/plaat/mtdf.html) реализация альфа-бета довольно сильно отличается от других, которые я обнаружил (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 не используется, поэтому что-то в использовании должно быть неправильным.

...