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.
// 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 ***
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
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;
}