From: H.G.Muller Date: Mon, 6 Feb 2017 21:35:25 +0000 (+0100) Subject: Implement history heuristic X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=2d038fb2010cafb77eca39030f5951ae395cb6f0;p=crazywa.git Implement history heuristic The non-captures are now sorted by history score before searching them. --- diff --git a/dropper.c b/dropper.c index 0b19726..5acff77 100644 --- a/dropper.c +++ b/dropper.c @@ -71,6 +71,7 @@ int handVal[96], rawGain[97]; unsigned int moveStack[500*MAXPLY]; int killers[MAXPLY][2]; int path[MAXPLY], deprec[MAXPLY]; +int history[1<<16]; unsigned char checkHist[MAXMOVES+MAXPLY]; int repKey[512+20]; @@ -1077,6 +1078,12 @@ UnMake (StackFrame *f) //ply==0 || path[0]==0x0017b1 && (ply==1 || (ply==2)) int +HisComp (const void *x, const void*y) +{ + return history[*(int *)y & 0xFFFF] - history[*(int *)x & 0xFFFF]; +} + +int Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction, int maxDepth) { MoveStack m; StackFrame f; HashEntry *entry; @@ -1213,6 +1220,7 @@ if(PATH)printf("%d:%d:%d new iter moveStack[%d..%d]\n",ply,depth,iterDepth,m.fir if(PseudoLegal(stm, killer2)) moveStack[moveSP++] = moveStack[m.late], moveStack[m.late++] = killer2; // (original goes to end) m.drops = moveSP; // here we can sort based on history + if(moveSP > m.late) qsort(moveStack + m.late, moveSP - m.late, sizeof(int), &HisComp); m.stage = 1; if(moveSP > curMove) break; case 1: if(f.checker != CK_NONE) { @@ -1282,6 +1290,7 @@ printf("%d:%d:%d %2d. %08x %c%d%c%d %6d %6d %6d\n",ply,depth,iterDepth,curMove,m if(score > alpha) { int *tail; alpha = score; + history[moveStack[curMove] & 0xFFFF] += iterDepth*iterDepth; if(score >= beta) { // beta cutoff if(curMove >= m.nonCapts && moveStack[curMove] != killers[ply][1]) killers[ply][0] = killers[ply][1], killers[ply][1] = moveStack[curMove]; @@ -1684,7 +1693,7 @@ printf("# command: %s\n", inBuf); int main () { - int score; + int score, i; EngineInit(); SetMemorySize(1); // reserve minimal hash to prevent crash if GUI sends no 'memory' command GameInit("zh"); Setup(startPos); // to facilitate debugging from command line @@ -1696,6 +1705,7 @@ main () if(stm == engineSide) { // if it is the engine's turn to move, set it thinking, and let it move nodeCount = forceMove = undoInfo.move = abortFlag = 0; ReadClock(1); + for(i=0;i<1<<16;i++) history[i] = 0; //>>= 1; score = Search(stm^COLOR, -INF, INF, &undoInfo, maxDepth, 0, maxDepth); if(!undoInfo.move) { // no move, game apparently ended