From 0feb71bc0adf7595bd6a1ff55d258eb6fd2709f0 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Tue, 7 Feb 2017 23:14:03 +0100 Subject: [PATCH] Put depth limit on QS To combat search explosion, QS is limited to 10 ply. This is done by setting a globalvariable depthLimit when we enter QS. When the limit is reached, the side to move gets an initiative bonus of 150 on top of the static eval. --- dropper.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dropper.c b/dropper.c index 0d97fe6..50106e3 100644 --- a/dropper.c +++ b/dropper.c @@ -789,6 +789,7 @@ Dump (char *s) #define attacks (rawAttacks + 23) static int attackKey, rawAttacks[13*22]; +int depthLimit = MAXPLY; int MoveGen (int stm, MoveStack *m, int castle) @@ -1102,7 +1103,7 @@ int Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction, int maxDepth) { MoveStack m; StackFrame f; HashEntry *entry; - int oldSP = moveSP, *pvStart = pvPtr; + int oldSP = moveSP, *pvStart = pvPtr, oldLimit = depthLimit; int killer1 = killers[ply][0], killer2 = killers[ply][1], hashMove; int bestNr, bestScore, startAlpha, startScore, resultDepth, iterDepth=0, originalReduction = reduction; int hit, hashKeyH, ran=0, ipMask=0; @@ -1192,7 +1193,13 @@ if(hashMove && board[hashMove>>8&255] == 0) {char s[100];sprintf(s,"bad hash mov if(curEval >= beta) { ff->depth = 1; moveSP = oldSP; return curEval; } // stand-pat cutoff alpha = startScore = curEval; maxDepth = 0; // we will not fail low, so no extra iterations } - if(maxDepth <= 0 && board[toDecode[hashMove&255]] == 0) hashMove = 0; + if(maxDepth <= 0) { + if(board[toDecode[hashMove&255]] == 0) hashMove = 0; +#ifdef IDQS + if(ply >= depthLimit) { ff->depth = 1; moveSP = oldSP; return curEval + 150; } // hit depth limit; give hefty stm bonus + if(depthLimit == MAXPLY) depthLimit = ply+10; // we just entered pure QS; set up depth limit +#endif + } } else if(curEval >= beta && f.checker == CK_NONE) { int nullDepth = depth - 3; if(nullDepth < 0) nullDepth = 0; @@ -1229,7 +1236,7 @@ if(hashMove && board[hashMove>>8&255] == 0) {char s[100];sprintf(s,"bad hash mov bonus += bonus >> 1; int newEval = curEval + bonus; if(newEval > alpha) { - if(newEval >= beta) { ff->depth = 1; moveSP = oldSP; return newEval; } // stand-pat cutoff + if(newEval >= beta) { ff->depth = 1; moveSP = oldSP; depthLimit = oldLimit; return newEval; } // stand-pat cutoff alpha = startScore = newEval; maxDepth = 0; // we will not fail low, so no extra iterations } } @@ -1324,7 +1331,7 @@ int m=moveStack[curMove]; printf("%d:%d:%d %2d. %08x %c%d%c%d %6d %6d %6d\n",ply,depth,iterDepth,curMove,m,(m>>8&255)%22+'a',(m>>8&255)/22+1,toDecode[m&255]%22+'a',toDecode[m&255]/22+1,f.pstEval,score,bestScore); } - if(abortFlag) { moveSP = oldSP; return -INF; } + if(abortFlag) { moveSP = oldSP; depthLimit = oldLimit; return -INF; } // minimaxing if(f.depth < resultDepth) resultDepth = f.depth; @@ -1398,7 +1405,7 @@ if(PATH)printf("%d:%d:%d iter end, max=%d, alpha=%d start=%d\n", ply, depth,iter if(PATH || f.hashKey == 0x1348708590)printf("%d:%d Hash store %16llx, d=%d, checker=%x move=%s\n",ply,depth,f.hashKey,resultDepth,entry->checker,MoveToText(entry->move)); // return results - moveSP = oldSP; pvPtr = pvStart; + moveSP = oldSP; pvPtr = pvStart; depthLimit = oldLimit; ff->depth = resultDepth + 1 + originalReduction; // report valid depth as seen from parent return bestScore; } -- 1.7.0.4