Release King surroundings in late end-game
[hachu.git] / hachu.c
diff --git a/hachu.c b/hachu.c
index 13373d2..5893196 100644 (file)
--- a/hachu.c
+++ b/hachu.c
 #define PST_RETRACT (5*BW*BH+BH)\r
 #define PST_WFLYER  (6*BW*BH)\r
 #define PST_BFLYER  (6*BW*BH+BH)\r
-#define PST_END     (7*BW*BH)\r
+#define PST_LANCE   (7*BW*BH)\r
+#define PST_END     (8*BW*BH)\r
 \r
 typedef unsigned int Move;\r
 \r
@@ -801,7 +802,7 @@ AddPiece (int stm, PieceDesc *list)
   p[i].bulk = list->bulk;\r
   p[i].mobWeight = v > 600 ? 0 : v >= 400 ? 1 : v >= 300 ? 2 : v > 150 ? 3 : v >= 100 ? 2 : 0;\r
   if(Lance(list->range))\r
-    p[i].mobWeight = 5 + 3*(list->range[4]==X), p[i].pst = 0; // clear path but don't move forward\r
+    p[i].mobWeight = 0, p[i].pst = list->range[4] ? PST_NEUTRAL : PST_LANCE; // keep back\r
   for(j=stm+2; j<= last[stm]; j+=2) {\r
     if(p[j].promo >= i) p[j].promo += 2;\r
   }\r
@@ -999,7 +1000,8 @@ Init (int var)
     PST[PST_ADVANCE+s] = PST[PST_WFLYER-s-1] = 2*(5*i+i*i) - (i >= zone)*6*(i-zone+1)*(i-zone+1)\r
        - (2*j - BH + 1)*(2*j - BH + 1)/BH + BH/2\r
        - 50 - 35*(j==0 || j == BH-1) - 15*(j == 1 || BH-2); // advance-encouraging table\r
-    PST[PST_WFLYER +s] = PST[PST_END-s-1] = (i == zone-1)*40 + (i == zone-2)*20 - 20;\r
+    PST[PST_WFLYER +s] = PST[PST_LANCE-s-1] = (i == zone-1)*40 + (i == zone-2)*20 - 20;\r
+    PST[PST_LANCE  +s] = (PST[PST_STEPPER+j] - PST[PST_STEPPER+s])/2; \r
    }\r
    if(zone > 0) PST[PST_WPPROM+BW*(BH-1-zone) + j] += 10, PST[PST_BPPROM + BW*zone + j] += 10;\r
    if(j > (BH-1)/2 - 3 && j < BH/2 + 3)\r
@@ -1611,7 +1613,7 @@ Fortress (int forward, int king, int lion)
 }\r
 \r
 int\r
-Surround (int stm, int king, int start)\r
+Surround (int stm, int king, int start, int max)\r
 {\r
   int i, s=0;\r
   for(i=start; i<9; i++) {\r
@@ -1621,7 +1623,7 @@ Surround (int stm, int king, int start)
     v = p[piece].value;\r
     s += -(v > 70) & v;\r
   }\r
-  return (s > 512 ? 512 : s);\r
+  return (s > max ? max : s);\r
 }\r
 \r
 int\r
@@ -1637,7 +1639,7 @@ Ftest (int side)
 int\r
 Evaluate (int difEval)\r
 {\r
-  int wLion = ABSENT, bLion = ABSENT, wKing, bKing, score=mobilityScore, f, i, j;\r
+  int wLion = ABSENT, bLion = ABSENT, wKing, bKing, score=mobilityScore, f, i, j, max=512;\r
 \r
   if(p[WHITE+2].value == LVAL) wLion = p[WHITE+2].pos;\r
   if(p[BLACK+2].value == LVAL) bLion = p[BLACK+2].pos;\r
@@ -1679,6 +1681,7 @@ Evaluate (int difEval)
     score += (PST[PST_CENTER+wKing] - PST[PST_CENTER+bKing])*(32 - filling) >> 7;\r
     if(lead  > 100) score -= PST[PST_CENTER+bKing]*(32 - filling) >> 3; // white leads, drive black K to corner\r
     if(lead < -100) score += PST[PST_CENTER+wKing]*(32 - filling) >> 3; // black leads, drive white K to corner\r
+    max = 16*filling;\r
   }\r
 \r
 # ifdef FORTRESS\r
@@ -1689,7 +1692,7 @@ Evaluate (int difEval)
 # endif\r
 \r
 # ifdef KSHIELD\r
-  score += Surround(WHITE, wKing, 1) - Surround(BLACK, bKing, 1) >> 3;\r
+  score += Surround(WHITE, wKing, 1, max) - Surround(BLACK, bKing, 1, max) >> 3;\r
 # endif\r
 \r
 #endif\r
@@ -1701,11 +1704,11 @@ Evaluate (int difEval)
     int sq;\r
     if((wLion = kylin[WHITE]) && (sq = p[wLion].pos) != ABSENT) {\r
       int anchor = sq - PST[5*BW*BH - 1 - sq]; // FIXME: PST_ZONDIST indexed backwards\r
-      score += (512 - Surround(BLACK, anchor, 0))*(128 - filling)*PST[p[wLion].pst + sq] >> 15;\r
+      score += (512 - Surround(BLACK, anchor, 0, 512))*(128 - filling)*PST[p[wLion].pst + sq] >> 15;\r
     }\r
     if((bLion = kylin[BLACK]) && (sq = p[bLion].pos) != ABSENT) {\r
       int anchor = sq + PST[PST_ZONDIST + sq];\r
-      score -= (512 - Surround(WHITE, anchor, 0))*(128 - filling)*PST[p[bLion].pst + sq] >> 15;\r
+      score -= (512 - Surround(WHITE, anchor, 0, 512))*(128 - filling)*PST[p[bLion].pst + sq] >> 15;\r
     }\r
   }\r
 #endif\r