Moderator: Andres Valverde
Michael Sherwin wrote: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.
Any thoughts on this?
Uri Blass wrote:Michael Sherwin wrote:A nonrecursive alpha--beta search function
by Michael J Sherwin.
(unless someone has beat me to it)
- Code: Select all
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.
Any thoughts on this?
Michael,
like Alessandro i miss some ply-based "stack" for some structures with alpha, beta and that like.Uri Blass wrote:I learned that you should never use goto
I got rid of goto in Movei by having boolean varaible for stop_search so I think that it is better to have some bolean variable no_more_moves and have in the right places
if (no_more_moves) break;
Uri
Zach Wegner wrote:I've been using non-recursion for a while, and I like it. Remember, the main benefit isn't from speed, it's from having access to previous plies' information and the ability to start and stop searches from anywhere. There is not much speed difference, but I use it for SMP(not quite implemented yet though ), and there isn't much reason to use it unless you are planning to use DTS.
But besides that, the macros I use make it just as easy to read. Also, I use a bunch of gotos. They aren't really a problem, if you know where they are going. I am planning on one day going open source, if/when I manage to get my program to an acceptable level, so everyone can see it.
There is not much speed difference, but I use it for SMP(not quite implemented yet though ), and there isn't much reason to use it unless you are planning to use DTS.
If you claim that having a stack is significantly slower than the main advantage is clearly speed. I also do not think that stopping a search is a problem in recursive search and I have a variable stop_search and I have in many places in my code
if (stop_search)
{
undomove();
return 0;
}
Dann Corbit wrote:The cost of recursion is very small. It is (once per function) a push of parameters and return address. If you pass by reference or pointer, even a large object only occupies (sizeof address). Recursion is expensive if you pass large classes or structures by value, but that is a pretty rare occurance.
...
int funcA(int i){
char myvar[10];
//do stuff
}
int funcB(int i){
char myvar[2000];
//do stuff
}
eric_oldre wrote:Dann Corbit wrote:The cost of recursion is very small. It is (once per function) a push of parameters and return address. If you pass by reference or pointer, even a large object only occupies (sizeof address). Recursion is expensive if you pass large classes or structures by value, but that is a pretty rare occurance.
...
Dann, does the size of the local variables inside of the function affect performace much? Would you expect much of a difference for these two?
Eric
- Code: Select all
int funcA(int i){
char myvar[10];
//do stuff
}
int funcB(int i){
char myvar[2000];
//do stuff
}
Michael Sherwin wrote:A nonrecursive alpha--beta search function
by Michael J Sherwin.
(unless someone has beat me to it)
eric_oldre wrote:Would you expect much of a difference for these two?
Eric
- Code: Select all
int funcA(int i){
char myvar[10];
//do stuff
}
int funcB(int i){
char myvar[2000];
//do stuff
}
Uri Blass wrote:I also do not think that stopping a search is a problem in recursive search and I have a variable stop_search and I have in many places in my code
if (stop_search)
{
undomove();
return 0;
}
Tony van Roon-Werten wrote:eric_oldre wrote:Dann Corbit wrote:The cost of recursion is very small. It is (once per function) a push of parameters and return address. If you pass by reference or pointer, even a large object only occupies (sizeof address). Recursion is expensive if you pass large classes or structures by value, but that is a pretty rare occurance.
...
Dann, does the size of the local variables inside of the function affect performace much? Would you expect much of a difference for these two?
Eric
- Code: Select all
int funcA(int i){
char myvar[10];
//do stuff
}
int funcB(int i){
char myvar[2000];
//do stuff
}
IIRC there is a difference once you go over 128 byte. But I don't know how much.
Tony
Dann Corbit wrote:Not sure why there would be any difference for uninitialized auto variables.
Generally speaking, if you look at the assembly, stack frame variables are allocated with a simple subtraction against the stack. Big parameter varables (other than arrays which are passed by pointer) consume time because they also have to be duplicated (involving memcpy for sizeof object).
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 34 guests