A non recursive search function!
Posted: 02 Dec 2005, 15:01
A nonrecursive alpha--beta search function
by Michael J Sherwin.
(unless someone has beat me to it)
int Search(alpha, beta, depth) {
int score;
int temp;
int ply;
int betaCut;
ply = 1;
betaCut = FALSE;
GenMoves();
while(ply) {
do {
if(betaCut || !MakeNextMove()) {
betaCut = FALSE;
goto noMoreMoves();
}
ply++;
temp = alpha;
alpha = -beta;
beta = -temp;
} while(depth-- && GenMoves());
score = Eval();
if(score > alpha) {
if(score >= beta)
betaCut = TRUE;
else
alpha = score;
}
noMoreMoves:
if(ply--) {
TakeBackMove();
depth++;
temp = alpha;
alpha = -beta;
beta = -temp;
}
}
return alpha;
}
Due to time restraints, I have not tested it.
See RomiChess, learn.c, LearnToHash() for a
similar approach.
[b]Any thoughts on this? [/b]
by Michael J Sherwin.
(unless someone has beat me to it)
int Search(alpha, beta, depth) {
int score;
int temp;
int ply;
int betaCut;
ply = 1;
betaCut = FALSE;
GenMoves();
while(ply) {
do {
if(betaCut || !MakeNextMove()) {
betaCut = FALSE;
goto noMoreMoves();
}
ply++;
temp = alpha;
alpha = -beta;
beta = -temp;
} while(depth-- && GenMoves());
score = Eval();
if(score > alpha) {
if(score >= beta)
betaCut = TRUE;
else
alpha = score;
}
noMoreMoves:
if(ply--) {
TakeBackMove();
depth++;
temp = alpha;
alpha = -beta;
beta = -temp;
}
}
return alpha;
}
Due to time restraints, I have not tested it.
See RomiChess, learn.c, LearnToHash() for a
similar approach.
[b]Any thoughts on this? [/b]