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];
//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;
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) {
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];
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
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