Stuck on Alphabeta
Posted: Mon Dec 07, 2015 1:58 pm
After studying basics chess engines (mainly TSCP and VICE) I'm trying to write my own chess engine for pure fun.
My doubt today (actually not just one ) is about Alphabeta.
From Bruce Moreland's archives (and almost everywhere in the net) I've found the following code:
Now, looking at TSCP and VICE I found a slightly variation:
So my question now should be pretty simple. Are they different in term of results? Are both good? Or I'm I supposed to use the second one?
If alpha < beta they does the same thing, otherwise the result should be different.
I'm sorry if my question has been asked somewhere and even if it looks pretty stupid, but I'm just trying to understand and I haven't found an answer elsewhere. And the desidere to learn isn't a fault yet .
Thanks in advance,
Luca
My doubt today (actually not just one ) is about Alphabeta.
From Bruce Moreland's archives (and almost everywhere in the net) I've found the following code:
Code: Select all
int AlphaBeta(int depth, int alpha, int beta)
{
if (depth == 0)
return Evaluate();
GenerateLegalMoves();
while (MovesLeft()) {
MakeNextMove();
val = -AlphaBeta(depth - 1, -beta, -alpha);
UnmakeMove();
if (val >= beta)
return beta;
if (val > alpha)
alpha = val;
}
return alpha;
}
Code: Select all
int AlphaBeta(int depth, int alpha, int beta)
{
if (depth == 0)
return Evaluate();
GenerateLegalMoves();
while (MovesLeft()) {
MakeNextMove();
val = -AlphaBeta(depth - 1, -beta, -alpha);
UnmakeMove();
if (val > alpha) {
if (val >= beta)
return beta;
alpha = val;
}
}
return alpha;
}
If alpha < beta they does the same thing, otherwise the result should be different.
I'm sorry if my question has been asked somewhere and even if it looks pretty stupid, but I'm just trying to understand and I haven't found an answer elsewhere. And the desidere to learn isn't a fault yet .
Thanks in advance,
Luca