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;
}
}
OK, you are right on the MinValue/MaxValue thing.
I’m a bit rusty about NegaMax and AlphaBeta but when I see
You’re testing
>for both limits, that doesn’t seem right.Edit: It seems just a naming/understanding issue of sorts. Your
AlphaBeta()method could be named more accuratelyNegaMaxWithAlphaBeta(). Because of the alternating roles of alpha and beta in NegaMax the naming of those parameters is not an exact match with MiniMax.Yes it should occur. And it’s only a beta-cutoff at the even ply-levels. At the odd levels,
if (eval >= beta)tests for an alpha-cutoff.I think you are using a narrowing alpha/beta window.
But maybe this answer can help you explain your problem better.