Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Where can I find a good working sample code of alpha-beta code

Author: Bruce Moreland

Date: 03:18:26 08/04/00

Go up one level in this thread


On August 02, 2000 at 22:29:07, Larry Griffiths wrote:

>I am looking for a simple code sample of alpha-beta (with negamax maybe).
>Would someone post an example here, or direct me to a good URL?
>
>Larry.

Alpha-Beta:

int ab(int alpha, int beta, int depth)
{
    if (depth == 0)
        return eval();
    while (moves()) {
        int val;

        make_move();
        val = -ab(-beta, -alpha, depth - 1);
        unmake_move();
        if (val >= beta)
            return beta;
        if (val > alpha)
            alpha = val;
    }
    return alpha;
}

The above doesn't handle checkmate and stalemate.  Negamax or PVS or whatever is
cool but it's more complex and it's only a 10% speed enhancement, so if you
haven't got alpha-beta right yet, get that right first.

Alpha-beta is very similar to min-max.  If you want to do min-max, just take out
the "if (val >= beta)" line and the line following it.

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.