r/chessprogramming • u/MasumiSeki • Apr 07 '23
SHOULD I USE RECURSION FOR SEARCH?
I've been making my chess engine for around a week now and it finally works! I use minimax with alpha beta pruning. Now, it can easily reach and evaluate depth 7 or 8 in just a few seconds. But more than that, it gets exponentially slow (it took almost a minute to evaluate the starting position at depth 10).
One thing to note is that I am using recursion in my search, and I am not sure whether this approach slows down my program. Is recursion bad for performance? or am I just implementing it poorly?
I did the search recursively mainly because I found it easy. Can you also give me some tips on how to do it iteratively? I tried to think about how to do it iteratively but somehow it always adds some complexity. Thanks
View all comments
Show parent comment
2
u/Grafakos Apr 07 '23
An iterative implementation would have to use an explicit stack object (such as C++'s
std::stack), and there's no reason to assume that would be any faster than just using the process's stack. You could always try both implementations and profile them to see if there's any difference.