AlphaBeta shouldn't exceed beta ?
Posted: 28 Jul 2010, 12:34
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 ?
Full code is here.
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 ?
Full code is here.
- Code: Select all
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;