{\r
int i, j, k, firstMove, oldMSP = msp, curMove, sorted, bad, phase, king, iterDep, replyDep, nextVictim, to, defer, dubious, bestMoveNr;\r
int savHashL = hashKeyL, savHashH = hashKeyH;\r
- int score, bestScore, curEval;\r
+ int score, bestScore, curEval, iterAlpha;\r
Move move, nullMove;\r
UndoInfo tb;\r
if(PATH) printf("search(%d) %d-%d eval=%d, stm=%d\n",depth,alpha,beta,difEval,stm),fflush(stdout);\r
alpha -= (alpha < curEval);\r
beta -= (beta <= curEval);\r
\r
- firstMove = curMove = sorted = nonCapts = msp += 20; // leave 20 empty slots in front of move list\r
+ firstMove = curMove = sorted = msp += 20; // leave 20 empty slots in front of move list\r
phase = 0; iterDep=1; replyDep = (depth < 1 ? depth : 1) - 1;\r
do {\r
if(flag && depth>= 0) printf("iter %d:%d\n", depth,iterDep),fflush(stdout);\r
- bestScore = -INF; bestMoveNr = 0;\r
+ iterAlpha = alpha; bestScore = -INF; bestMoveNr = 0;\r
for(curMove = firstMove; ; curMove++) { // loop over moves\r
if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase, firstMove, curMove, msp);fflush(stdout);\r
// MOVE SOURCE\r
#if 0\r
if(curEval >= beta) {\r
stm ^= WHITE;\r
- score = -Search(-beta, -alpha, difEval, depth-3, promoSuppress & SQUARE, ABSENT);\r
+ score = -Search(-beta, -iterAlpha, difEval, depth-3, promoSuppress & SQUARE, ABSENT);\r
stm ^= WHITE;\r
if(score >= beta) { msp = oldMSP; return score + (score < curEval); }\r
}\r
if(depth <= 0) goto cutoff;\r
phase = 6;\r
case 6: // non-captures\r
+ nonCapts = msp;\r
nullMove = GenNonCapts(oldPromo);\r
phase = 7;\r
sorted = msp; // do not sort noncapts\r
if(score == -INF) { moveStack[curMove] = 0; goto abortMove; }\r
}\r
#if 1\r
- score = -Search(-beta, -alpha, -difEval - tb.booty, replyDep, promoSuppress & ~PROMOTE, defer);\r
+ score = -Search(-beta, -iterAlpha, -difEval - tb.booty, replyDep, promoSuppress & ~PROMOTE, defer);\r
#else\r
score = 0;\r
#endif\r
// ALPHA-BETA STUFF\r
if(score > bestScore) {\r
bestScore = score; bestMoveNr = curMove;\r
- if(score > alpha) {\r
- alpha = score;\r
+ if(score > iterAlpha) {\r
+ iterAlpha = score;\r
if(curMove < firstMove + 5) { // if not too much work, sort move to front\r
int i;\r
for(i=curMove; i>firstMove; i--) {\r
if(!(flags & promoBoard[t] & (CANT_DEFER | LAST_RANK))) { // but change it into a deferral if that is allowed\r
moveStack[i] &= ~PROMOTE;\r
if(p[board[f]].value == 40) p[board[f]].promoFlag &= LAST_RANK; else\r
- if(!(flags & promoBoard[t])) moveStack[i] |= DEFER; // came from outside zone, so essential deferral\r
+ if(!(flags & promoBoard[f])) moveStack[i] |= DEFER; // came from outside zone, so essential deferral\r
}\r
}\r
if(i >= retMSP)\r
- for(i=20; i<retMSP; i++) printf("# %d. %08x %08x %s\n", i-20, moveStack[i], ret, MoveToText(moveStack[i], 0));\r
+ for(i=retFirst; i<retMSP; i++) printf("# %d. %08x %08x %s\n", i-20, moveStack[i], ret, MoveToText(moveStack[i], 0));\r
}\r
return (i >= retMSP ? INVALID : moveStack[i]);\r
}\r
if(!cnt) { // no moves from given square\r
if(sqr != lastPut) return; // refrain from sending empty FEN\r
// we lifted a piece for second leg of move\r
- for(i=20; i<retMSP; i++) {\r
+ for(i=retFirst; i<retMSP; i++) {\r
if(lastLift == (moveStack[i]>>SQLEN & SQUARE)) {\r
int e, t = moveStack[i] & SQUARE;\r
if(t < SPECIAL) continue; // only special moves\r