Keep track of total hand values
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sat, 14 Jan 2017 10:30:20 +0000 (11:30 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sat, 14 Jan 2017 10:30:20 +0000 (11:30 +0100)
With the aidof two new tables, handBulk[] (piece-list size) and dropBulk[]
(board sized), we now keep track of the total value of pieces in the hands.
This is stored in the promoGain for piece type 30, (which is not used in
any variant), to easily index it with the side to move.

dropper.c

index 8087bf5..d0e9a35 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -54,6 +54,7 @@ int moveNr;              // part of game state; incremented by MakeMove
 #define zoneTab  (rawByte + 48*22)
 #define sqr2file (rawByte + 59*22)
 #define dist     (rawByte + 70*22 + 22*10 + 10)
+#define dropBulk (rawByte + 91*22)
 #define location (rawLocation + 23)
 #define promoGain (rawGain + 1)
 
@@ -61,7 +62,7 @@ int pvStack[MAXPLY*MAXPLY/2];
 int nrRanks, nrFiles, specials, pinCodes, maxDrop, moveSP, pawn, lanceMask, *pvPtr = pvStack, boardEnd, perpLoses, searchNr;
 int rawInts[21*22], pieceValues[96], pieceCode[96];
 signed char   rawChar[32*22], steps[512];
-unsigned char rawByte[91*22], firstDir[64], rawBulk[98], handSlot[97], promoCode[96], aVal[64], vVal[64], rawLocation[96+23];
+unsigned char rawByte[102*22], firstDir[64], rawBulk[98], handSlot[97], promoCode[96], aVal[64], vVal[64], rawLocation[96+23], handBulk[96];
 long long int handKey[96], pawnKey;
 int handVal[96], rawGain[97];
 unsigned int moveStack[500*MAXPLY];
@@ -421,6 +422,7 @@ ClearBoard ()
     for(r=0; r<nrRanks; r++) for(f=0; f<nrFiles; f++) board[22*r+f] = 0; // playing area
     for(f=0; f<11; f++) pawnCount[f] = 0xF0;      // Pawn occupancy per file
     for(i=0; i<512+20; i++) repKey[i] = 0;        // game-history hash
+    promoGain[WHITE+30] = promoGain[BLACK+30] = 0;// danger measure of in-hand pieces
 }
 
 char *pieces, *startPos;
@@ -548,6 +550,8 @@ printf("# variant %d: %s\n", v, variants[v].name);
     for(i=0; i<16; i++) {
        int demoted = dropType[handSlot[WHITE+i+16]]-1; // piece type after demotion (could be Pawn, in Chess)
        handVal[WHITE+i+16] = handVal[BLACK+i+16] = pieceValues[WHITE+i+16] + handVal[demoted];   // gain by capturing promoted piece
+       handBulk[WHITE+i] = handBulk[BLACK+i] = pieceValues[WHITE+i]/80;
+       handBulk[WHITE+i+16] = handBulk[BLACK+i+16] = pieceValues[demoted]/80;
     }
     for(i=0; i<16; i++) handVal[WHITE+i] = handVal[BLACK+i] += pieceValues[WHITE+i];  // gain by capturing base piece
     for(i=0; i<16; i++) {
@@ -564,6 +568,7 @@ printf("# variant %d: %s\n", v, variants[v].name);
     }
     for(i=0; i<16; i++) { // PST for in-hand pieces. type = -1 only occurs on (all) drops, but true type determined by (off-board) square
        PST[-1][handSlot[WHITE+i]] = PST[-1][handSlot[BLACK+i]] = handVal[WHITE+i] - 2*pieceValues[WHITE+i];
+       dropBulk[handSlot[WHITE+i]] = dropBulk[handSlot[BLACK+i]] = pieceValues[WHITE+i]/80;
     }
     PST[WHITE+2] = PST[BLACK+2] = center; // Bishops
     for(f=0; f<11; f++) { // pawn tables
@@ -643,9 +648,11 @@ Debug ()
     printf("\nfarCode:\n"); for(i=0; i<96; i++) printf(" %2x%s", pieceCode[i]>>8 & 255, (i&15) == 15 ? "\n" : "");
     PrintValues("pieceValues:", pieceValues, 0);
     PrintValues("handVal:", handVal, 0);
-    PrintValues("promoGain:", promoGain, 96);
+    PrintValues("promoGain:", promoGain, 64);
     PrintPieces("vVal:", vVal, 64);
     PrintPieces("aVal:", aVal, 64);
+    PrintPieces("handBulk:", handBulk, 96);
+    PrintDBoard("dropBulk", dropBulk, "   ", 11);
     PrintDBoard("hand PST:", PST[-1], "   ", 11);
     PrintDBoard("Pawn PST:", PST[WHITE], "   ", 11);
     PrintDBoard("board:", board, "   ", 11);
@@ -669,7 +676,7 @@ typedef struct {
     Key hashKey, newKey;
     unsigned char fromSqr, toSqr, captSqr, epSqr, rookSqr, rights;
     signed char fromPiece, toPiece, victim, savePiece, rook, mutation;
-    int pstEval, newEval;
+    int pstEval, newEval, bulk;
     int move, depth;
     int checker, checkDir, checkDist, xking;
 } StackFrame;
@@ -938,7 +945,7 @@ NonEvade (StackFrame *f)
 int
 MakeMove (StackFrame *f, int move)
 {
-    int to;
+    int to, stm;
     f->fromSqr = move >> 8 & 255;
     to = move & 255;
     f->toSqr = f->captSqr = toDecode[to];                               // real to-square for to-encoded special moves
@@ -990,6 +997,8 @@ MakeMove (StackFrame *f, int move)
     f->newEval += promoGain[f->toPiece] - promoGain[f->mutation]                                        + handVal[f->victim] +
                  PST[f->toPiece][f->toSqr] - PST[f->mutation][f->fromSqr] + PST[f->victim][f->captSqr];
     f->newKey  += KEY(f->toPiece, f->toSqr) - KEY(f->mutation, f->fromSqr) - KEY(f->victim, f->captSqr) + handKey[f->victim];
+    stm = f->toPiece & COLOR;
+    f->bulk = promoGain[stm+30]; promoGain[stm+30] += handBulk[f->victim] - dropBulk[f->fromSqr];
     location[f->toPiece] = f->toSqr;
 
     return 1;
@@ -1003,6 +1012,7 @@ UnMake (StackFrame *f)
     board[f->captSqr] = f->victim;    // differs from toSqr on e.p. (Pawn to-square) and castling, (King to-square) and should be cleared then
     board[f->fromSqr] = f->fromPiece; //          and the mover
     board[handSlot[f->victim]]++;
+    promoGain[(f->toPiece & COLOR)+30] = f->bulk;
     location[f->fromPiece] = f->fromSqr;
 }
 
@@ -1347,6 +1357,7 @@ Setup (char *fen)
       board[sqr]--;                                   // count piece in hand      
       hashKey += handKey[i ^ COLOR];                  // update hash key
       pstEval += (color & WHITE ? 1 : -1)*(handVal[i] - pieceValues[i]); // update PST eval (white POV)
+      promoGain[color+30] += handBulk[i];
     }
     fen++;    // skip closing bracket
   }