Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: outline for alpha beta

Author: Bruce Moreland

Date: 14:40:06 05/12/00

Go up one level in this thread


On May 12, 2000 at 13:34:39, John Coffey wrote:

>My evaluation function is partially complete.
>I have move generation done, so now it is time to add the
>alpha beta search.
>
>I have seen pseudo code for alpha beta before but can no longer
>find it.  Could someone please direct me to a source.
>
>I have been confused by the terms "fail high" and "fail low"
>although I think that I understand the principles behind it.
>
>I would also like to see pseudo code for null move pruning.
>
>Thanks in advance,
>
>John Coffey

int search(int alpha, int beta, int depth)
{
    if (depth <= 0)
        return eval();
    while (more_moves()) {
        int cur;

        make_next_move();
        cur = -search(-beta, -alpha, depth - 1);
        unmake_move();
        if (cur >= beta)
            return beta;  // Fail high.
        if (cur > alpha)
            alpha = cur;  // PV.
    }
    return alpha;  // Fail-low, if "alpha = cur" never was
}                  //  executed, otherwise PV.

You call this with "search(-32767, 32767, 8)" to do an 8-ply search.  It returns
the value of the position, but doesn't return the best move or the PV.  That's a
pretty minor enhancement.

If you want a normal min-max search, just take out the two lines that do
fail-high.

bruce



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.