Remember ply level at which position previously occurred
authorH.G.Muller <hgm@hgm-xboard.(none)>
Mon, 15 May 2017 12:38:54 +0000 (14:38 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Mon, 15 May 2017 12:42:53 +0000 (14:42 +0200)
By storing the ply level of each latest occurrence of a position,
wecan know how far back to test for perpetuals.

dropper.c

index b21690d..f607d32 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -76,7 +76,8 @@ int path[MAXPLY], deprec[MAXPLY];
 int history[1<<16], mateKillers[1<<17];
 int anaSP;
 unsigned char checkHist[MAXMOVES+MAXPLY];
-int repKey[512+20];
+int repKey[512+100];
+unsigned char repDep[512+100];
 
 /*
    Drops: piece is the (negated) count, promo the piece to be dropped.
@@ -1330,7 +1331,8 @@ if(PATH)printf("%d:%d:%d new iter moveStack[%d..%d]\n",ply,depth,iterDepth,m.fir
                // repetition checking
                int index = (unsigned int)f.newKey >> 24 ^ stm << 2; // uses high byte of low (= hands-free) key
                while(repKey[index] && (repKey[index] ^ (int)f.newKey) & 0x1FFFFF) index += 2;
-               if(repKey[index]) { // key present in table: (quasi-)repetition
+               int oldRepKey = repKey[index], oldRepDep = repDep[index];
+               if(oldRepKey && ff->mutation != -2) { // key present in table: (quasi-)repetition
                    int gain = (f.newEval << 21) - (repKey[index] & 0xFFE00000);
                    if(gain == 0) { // true repeat
                        score = 0; // draw score *** HERE WE SHOULD TEST FOR PERPETUALS IN SHOGI ***
@@ -1343,13 +1345,13 @@ if(PATH)printf("%d:%d:%d new iter moveStack[%d..%d]\n",ply,depth,iterDepth,m.fir
                    lmr = (curMove >= m.late) + (curMove >= m.drops);
                    f.tpGain = f.newEval + ff->pstEval;     // material gain in last two ply
                    if(ply==0 && randomize && moveNr < 10) ran = (alpha > INF-100 || alpha <-INF+100 ? 0 : (f.newKey*ranKey>>24 & 31)- 16);
-                   repKey[index] = (int)f.newKey & 0x1FFFFF | f.newEval << 21; // remember position
+                   repKey[index] = (int)f.newKey & 0x1FFFFF | f.newEval << 21; repDep[index] = ply + moveNr; // remember position
                    // recursion
                    deprec[ply] = (f.checker != CK_NONE ? f.checker : 0)<<24 | maxDepth<<16 | depth<< 8 | iterDepth; path[ply++] = moveStack[curMove];
                    score = ran - Search(stm, -beta, -alpha+ran, &f, iterDepth-1, lmr, highDepth);
                    ply--;
 
-                   repKey[index] = 0;
+                   repKey[index] = oldRepKey; repDep[index] = oldRepDep;
                }
 
                // unmake
@@ -1650,6 +1652,7 @@ RootMakeMove(int move)
   index = (unsigned int)undoInfo.newKey >> 24 ^ stm << 2; // uses high byte of low (= hands-free) key
   while(repKey[index] && (repKey[index] ^ (int)undoInfo.newKey) & 0x1FFFFF) index += 2; // find empty slot
   repKey[index] = (int)undoInfo.newKey & 0x1FFFFF | undoInfo.newEval << 21; // remember position
+  repDep[index] = moveNr;
   stm ^= COLOR; moveNr++;
   return 1;
 }