views:

89

answers:

2

Hello everybody.

I have experienced AlphaBeta algorithm with my own old chess engine and now i am trying to write new engine and i see that algorithim encounter beta cut-offs but in my opinion, this should never be occur if i don't use narrowed window. Am i wrong ? I am using int.MaxValue for beta and -int.MaxValue for alpha so what can cause a beta cut-offs ?

Edit:

Full code is here.

    public Result Search(int maxDepth)
    {
        int alpha = -int.MaxValue, beta = int.MaxValue, ply = maxDepth;
        var bestLine = new Stack<Move>();

        var score = AlphaBeta(alpha, beta, ply, bestLine);

        return new Result(score, bestLine);
    }
    int AlphaBeta(int alpha, int beta, int ply, Stack<Move> bestLine)
    {
        if (ply <= 0) return Evaluation.Evaluate(Board);
        var moves = Board.GenerateMoves();
        foreach (var move in moves)
        {
            Board.MakeMove(move);

            eval = -AlphaBeta(-beta, -alpha, ply - 1, bestLine);

            Board.TakeBackMove(move);

            if (eval >= beta)
            {
                return beta;
            }
            if (eval > alpha)
            {
                alpha = eval;
                if (ply == 1) bestLine.Clear();

                bestLine.Push(move);
            }
        }
        return alpha;
    }
}
+1  A: 
Henk Holterman
Articles about AlphaBeta proves that it is not wrong. But really i will get crazy that where comes this mistake. do u also agree that never beta cut-offs should be ? Because it is full window search.
Freshblood
Back to basics - do you see _wrong_ beta-cutoff or don't you expect beta cutting at all? Ie is the line `return beta` being executed?
Henk Holterman
See for instance [wikipedia](http://en.wikipedia.org/wiki/Alpha-beta_pruning), in the pseudocode there only is a beta-cut, no alpha...
Henk Holterman
Yes, return beta is executing and my assume that this should never been happen.
Freshblood
It's the point where alpha/beta __is helping__ ... You don't have an alpha cutoff, so if there was no `return beta` you might as well drop the whole pruning.
Henk Holterman
AlphaBeta algorithim is not easy as it looks. If there is no alpha return or beta, it means u use narrowed alpha and beta values. In full windows search(max values for alpha and beta) only alpha can return.
Freshblood
without the return beta, where else is your tree being pruned?
Henk Holterman
I hadn't understand this algorithm very well thats why my assumng wasn't right. I just confused it with aspiration window extension. I think this time u are right. I use AlphaBeta not MinMax so beta cut-offs occur. This is not bug. I think the problem is occur on collection principal variation so i will try to fix it. Thanks your effort.
Freshblood
+1  A: 

Notice that in your recursion you pass the parameters in reverse order:

eval = -AlphaBeta(-beta, -alpha, ply - 1, bestLine);

Reversed from the way they are declared:

int AlphaBeta(int alpha, int beta, int ply, Stack bestLine)

So they change roles at each ply. Alpha can be updated, and that's equivalent to a reduction in beta on deeper levels of the tree.

To me this looks like an odd mix of Alpha/Beta and Negamax since both players are trying to reduce the score, which is negated at each level.

phkahler