Please help with using PV moves in Alpha-beta

Discussion of chess software programming and technical issues.

Moderator: Ras

Aleks Peshkov
Posts: 894
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Please help with using PV moves in Alpha-beta

Post by Aleks Peshkov »

Code: Select all

NodeControl NodeAb::visit(Move move) {
    if (!control.countNode()) { return Abort; }
    
    playMove(move);

    if (movesCount == 0) {
        //mated or stalemated
        score = StaticEval();
    }
    else if (draft == 0) {
        score = StaticEval(); // QS in TODO
    }
    else {
        alpha = -parent.beta;
        beta = -parent.alpha;
        if (visitChildren() == Abort); { return Abort; }
    }

    if (parent.score < -score) {
        parent.score = -score;
        control.setPv(parent.ply, move);

        if (parent.alpha < parent.score) {
            parent.alpha = parent.score;

            if (parent.alpha >= parent.beta) {
                return BetaCutoff;
            }
        }
    }

    return Continue;
}

NodeControl NodeAb::visitChildren() {
    score = Score::Minimum;
    
    //create a new empty node that will be used for all children moves
    auto child = NodeAb{*this};

    //THE QUESTION OF THE TOPIC, HOW TO USE IT?
    auto move = control.pv[0][ply];
    if (move) {
        if (isLegalMove(move)) {
            RETURN_IF_CUTOFF_OR_ABORT (child.visit(move));
        }
    }

    for (auto move : generateMove()) {
        RETURN_IF_CUTOFF_OR_ABORT (child.visit(move));
    }

    return Continue;
}
So far PV move is used as the killer move anywhere it is possible. But how to use PV moves from previous iteration correctly?