ZirconiumX wrote:...and now my QSearch is causing an explosion
Hi Matthew,
currently I have no important comment on your QSearch, it does not look as if it could do much harm. But I strongly suggest that you fix all compiler warnings, since I know that some of them point to bugs. I have compiled the code you published via the link above using VS2010 Express, and got a lot of warnings that are definitely bugs.
Mainly these are making trouble (but you should better fix ALL warnings):
Code: Select all
// tran.cpp (this warning appears many times in zobristKey() and
// lets that function effectively return complete random,
// which makes your hash table code do the same
if (side == BLACK)
key ^ blackToMove;
// must be: key ^= blackToMove;
// same at many other places
// srch.cpp (this one does actually not do any harm but the line is
// simply useless, and in other cases such code could really screw you up)
seldepth == 0;
// eval.cpp (unitialized variables, this bug lets you practically never
// identify an endgame
int IsEnding()
{
int wpawn, wknight, wbishop, wrook, wqueen, bpawn, bknight, bbishop, brook, bqueen;
for (int i = 0; i < 64; i++) {
if (color[i] == WHITE) {
if (piece[i] == PAWN)
wpawn++;
if (piece[i] == KNIGHT)
wknight++;
...
There is even more. Have you run your program in a debugger, and compiled it without /NDEBUG? If you didn't than you definitely should, I can assure you that you will see a lot of surprises
Please set a breakpoint on each line that contains "assert(false)".
One other issue that is very important to fix is that in AlphaBeta(), the variables score and f_prune are not initialized but used within this condition:
Code: Select all
if (score + VALUE_BISHOP <= alpha &&
depth == 1 &&
f_prune &&
!IsInCheck(side) &&
i < moves - 1)
return alpha;
This leads to an immediate return of AlphaBeta() through this branch, or the next one (for depth == 2) which is similar. While I can't tell exactly what the meaning of that piece of code is (it seems to be futility pruning, but then you would not want to RETURN to the parent node, just to SKIP the current move!), I am sure that the missing values for 'score' and 'f_prune' cause your tree to be very small (AlphaBeta() seems to always return after expanding just the first move one ply deep - I did not add your QSearch code yet). 'score' will be set after having searched the first move, or (which is a bad side effect, you should use a local score variable there!) in the block for null move if that one is entered, but it will in general not be set when dealing with the first move.
I think there is considerable work to be done. But this is also part of the fun
EDIT: some of my points are now also covered by another post as I have just seen.
Sven