Pass difEval on to root search
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 1f0fcfc..3ea5599 100644 (file)
--- a/hachu.c
+++ b/hachu.c
@@ -84,7 +84,7 @@ typedef struct {
   int from, to, piece, victim, new, booty, epSquare, epVictim, ep2Square, ep2Victim, savKeyL, savKeyH;\r
 } UndoInfo;\r
 \r
-int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, retMSP, retFirst, level, chuFlag=1;\r
+int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, level, chuFlag=1;\r
 int nodes, startTime, tlim1, tlim2;\r
 Move retMove, moveStack[10000], path[100];\r
 \r
@@ -675,10 +675,13 @@ AddMove (int i, int x, int y)
 }\r
 #endif\r
 \r
+int flag;\r
+\r
 inline int\r
 NewNonCapture (int x, int y, int promoFlags)\r
 {\r
   if(board[y] != EMPTY) return 1; // edge, capture or own piece\r
+//if(flag) printf("# add %c%d%c%d, pf=%d\n", x%BW+'a',x/BW,y%BW+'a',y/BW, promoFlags);\r
   if( (promoBoard[x] | promoBoard[y]) & promoFlags) { // piece can promote with this move\r
     moveStack[msp++] = moveStack[nonCapts];           // create space for promotion\r
     moveStack[nonCapts++] = x<<SQLEN | y | PROMOTE;   // push promotion\r
@@ -690,6 +693,7 @@ NewNonCapture (int x, int y, int promoFlags)
     }\r
   } else\r
     moveStack[msp++] = x<<SQLEN | y; // push normal move\r
+//if(flag) printf("msp=%d nc=%d\n", msp, nonCapts);    \r
   return 0;\r
 }\r
 \r
@@ -1182,8 +1186,6 @@ Evaluate ()
   return 0;\r
 }\r
 \r
-int flag;\r
-\r
 int\r
 Search (int alpha, int beta, int difEval, int depth, int oldPromo, int promoSuppress)\r
 {\r
@@ -1468,12 +1470,14 @@ MakeMove2 (int stm, MOVE move)
 {\r
   sup0 = sup1; sup1 = sup2;\r
   sup2 = MakeMove(move, &undoInfo);\r
+  rootEval = -rootEval - undoInfo.booty;\r
   return stm ^ WHITE;\r
 }\r
 \r
 void\r
 UnMake2 (MOVE move)\r
 {\r
+  rootEval = -rootEval - undoInfo.booty;\r
   UnMake(&undoInfo);\r
   sup2 = sup1; sup1 = sup0;\r
 }\r
@@ -1483,6 +1487,7 @@ Setup2 (char *fen)
 {\r
   SetUp(chuArray, chuPieces);\r
   sup0 = sup1 = sup2 = ABSENT;\r
+  rootEval = 0;\r
   return WHITE;\r
 }\r
 \r
@@ -1553,6 +1558,7 @@ MapFromScratch(attacks);
   if(i>=retMSP) {  // no exact match\r
     if(deferred) { // but maybe non-sensical deferral\r
       int flags = p[board[f]].promoFlag;\r
+printf("# deferral of %d\n", deferred);\r
       i = deferred; // in any case we take that move\r
       if(!(flags & promoBoard[t] & (CANT_DEFER | LAST_RANK))) { // but change it into a deferral if that is allowed\r
        moveStack[i] &= ~PROMOTE;\r
@@ -1631,7 +1637,7 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti
   tlim2 = 1.9*targetTime;\r
   nodes = 0;\r
 MapFromScratch(attacks);\r
-  score = Search(-INF-1, INF+1, 0, 20, sup1, sup2);\r
+  score = Search(-INF-1, INF+1, rootEval, 20, sup1, sup2);\r
   *move = retMove;\r
   *ponderMove = INVALID;\r
   return score;\r