#define P_WHITE 0x0F\r
#define P_BLACK 0xF0\r
\r
+// Piece-Square Tables\r
+#define PST_NEUTRAL 0\r
+#define PST_STEPPER BH\r
+#define PST_WJUMPER (BW*BH)\r
+#define PST_SLIDER (BW*BH+BH)\r
+#define PST_TRAP (2*BW*BH)\r
+#define PST_CENTER (2*BW*BH+BH)\r
+#define PST_WPPROM (3*BW*BH)\r
+#define PST_BPPROM (3*BW*BH+BH)\r
+#define PST_BJUMPER (4*BW*BH)\r
+#define PST_ZONDIST (4*BW*BH+BH)\r
+\r
typedef unsigned int Move;\r
\r
char *MoveToText(Move move, int m); // from WB driver\r
p[i].value = v = list->value;\r
for(j=0; j<8; j++) p[i].range[j] = list->range[j^4*(WHITE-stm)];\r
switch(Range(p[i].range)) {\r
- case 1: p[i].pst = BH; break;\r
- case 2: p[i].pst = bsize; break;\r
- default: p[i].pst = bsize + BH; break;\r
+ case 1: p[i].pst = PST_STEPPER; break;\r
+ case 2: p[i].pst = PST_WJUMPER; break;\r
+ default: p[i].pst = PST_SLIDER; break;\r
}\r
key = (stm == WHITE ? &list->whiteKey : &list->blackKey);\r
if(!*key) *key = ~(myRandom()*myRandom());\r
p[i].promoGain = (p[j].value - p[i].value - g)*1.25, p[i].value = p[j].value - g;\r
else p[i].promoGain = 0;\r
if(i == kylin[WHITE]) p[i].promoGain = 1.25*KYLIN, p[i].value += KYLIN;\r
- if(j > 0 && p[i].pst == BH) p[i].pst = 3*BW*BH; // use white pre-prom bonus\r
+ if(j > 0 && p[i].pst == PST_STEPPER) p[i].pst = PST_WPPROM; // use white pre-prom bonus\r
board[p[i].pos] = i;\r
rootEval += p[i].value + PST[p[i].pst + p[i].pos];\r
promoDelta += p[i].promoGain;\r
p[i].promoGain = (p[j].value - p[i].value - g)*1.25, p[i].value = p[j].value - g;\r
else p[i].promoGain = 0;\r
if(i == kylin[BLACK]) p[i].promoGain = 1.25*KYLIN, p[i].value += KYLIN;\r
- if(j > 0 && p[i].pst == BH) p[i].pst = 3*BW*BH + BH; // use black pre-prom bonus\r
- if(j > 0 && p[i].pst == bsize) p[i].pst = 4*BW*BH; // use white pre-prom bonus\r
+ if(j > 0 && p[i].pst == PST_STEPPER) p[i].pst = PST_BPPROM; // use black pre-prom bonus\r
+ if(j > 0 && p[i].pst == PST_WJUMPER) p[i].pst = PST_BJUMPER; // use black pre-prom bonus\r
board[p[i].pos] = i;\r
rootEval -= p[i].value + PST[p[i].pst + p[i].pos];\r
promoDelta -= p[i].promoGain;\r
for(j=0; j<BH; j++) {\r
for(i=0; i<BH; i++) {\r
int s = BW*i + j, d = BH*(BH-2) - abs(2*i - BH + 1)*(BH-1) - (2*j - BH + 1)*(2*j - BH + 1);\r
- PST[s] = 2*(i==0 | i==BH-1) + (i==1 | i==BH-2); // last-rank markers in null table\r
- PST[BH+s] = d/4 - (i < 2 || i > BH-3 ? 3 : 0) - (j == 0 || j == BH-1 ? 5 : 0)\r
- + 3*(i==zone || i==BH-zone-1); // stepper centralization\r
- PST[BH*BW+s] = d/6; // double-stepper centralization\r
- PST[BH*BW+BH+s] = d/12 - 5*(i==BH/2 || i==(BH-1)/2); // slider centralization\r
- PST[2*BH*BW+s] = j < 3 || j > BH-4 ? (i < 3 ? 7 : i == 3 ? 4 : i == 4 ? 2 : 0) : 0;\r
- PST[2*BH*BW+BH+s] = ((BH-1)*(BH-1) - (2*i - BH + 1)*(2*i - BH + 1) - (2*j - BH + 1)*(2*j - BH + 1))/6;\r
- PST[3*BH*BW+s] = PST[3*BH*BW+BH+s] = PST[BH+s]; // as stepper, but with pre-promotion bonus W/B\r
- PST[4*BH*BW+s] = PST[BW*BH+s]; // as jumper, but with pre-promotion bonus B\r
- PST[4*BH*BW+BH+s] = BW*(zone - 1 - i); // board step to enter promo zone black\r
+ PST[s] = 2*(i==0 | i==BH-1) + (i==1 | i==BH-2); // last-rank markers in null table\r
+ PST[PST_STEPPER+s] = d/4 - (i < 2 || i > BH-3 ? 3 : 0) - (j == 0 || j == BH-1 ? 5 : 0)\r
+ + 3*(i==zone || i==BH-zone-1); // stepper centralization\r
+ PST[PST_WJUMPER+s] = d/6; // double-stepper centralization\r
+ PST[PST_SLIDER +s] = d/12 - 5*(i==BH/2 || i==(BH-1)/2); // slider centralization\r
+ PST[PST_TRAP +s] = j < 3 || j > BH-4 ? (i < 3 ? 7 : i == 3 ? 4 : i == 4 ? 2 : 0) : 0;\r
+ PST[PST_CENTER+s] = ((BH-1)*(BH-1) - (2*i - BH + 1)*(2*i - BH + 1) - (2*j - BH + 1)*(2*j - BH + 1))/6;\r
+ PST[PST_WPPROM+s] = PST[PST_BPPROM+s] = PST[PST_STEPPER+s]; // as stepper, but with pre-promotion bonus W/B\r
+ PST[PST_BJUMPER+s] = PST[PST_WJUMPER+s]; // as jumper, but with pre-promotion bonus B\r
+ PST[PST_ZONDIST+s] = BW*(zone - 1 - i); // board step to enter promo zone black\r
}\r
- if(zone > 0) PST[3*BW*BH+BW*(BH-1-zone) + j] += 10, PST[3*BW*BH+BH + BW*zone + j] += 10;\r
+ if(zone > 0) PST[PST_WPPROM+BW*(BH-1-zone) + j] += 10, PST[PST_BPPROM + BW*zone + j] += 10;\r
#if KYLIN\r
// pre-promotion bonuses for jumpers\r
- if(zone > 0) PST[BW*BH + BW*(BH-2-zone) + j] = PST[4*BW*BH + BW*(zone+1) + j] = 100,\r
- PST[BW*BH + BW*(BH-1-zone) + j] = PST[4*BW*BH + BW*zone + j] = 200;\r
+ if(zone > 0) PST[PST_WJUMPER + BW*(BH-2-zone) + j] = PST[PST_BJUMPER + BW*(zone+1) + j] = 100,\r
+ PST[PST_WJUMPER + BW*(BH-1-zone) + j] = PST[PST_BJUMPER + BW*zone + j] = 200;\r
#endif\r
}\r
\r
if(bLion == ABSENT && p[BLACK+4].value == LVAL) bLion = p[BLACK+4].pos;\r
\r
#ifdef LIONTRAP\r
-# define lionTrap (PST + 2*BH*BW)\r
+# define lionTrap (PST + PST_TRAP)\r
// penalty for Lion in enemy corner, when enemy Lion is nearby\r
if(wLion != ABSENT && bLion != ABSENT) { // both have a Lion\r
static int distFac[36] = { 0, 0, 10, 9, 8, 7, 5, 3, 1 };\r
bKing = p[royal[BLACK]].pos; if(bKing == ABSENT) bKing = p[royal[BLACK]+2].pos;\r
if(filling < 32) {\r
int lead = (stm == WHITE ? difEval : -difEval);\r
- score += (PST[3*BW*BH+wKing] - PST[3*BW*BH+bKing])*(32 - filling) >> 7;\r
- if(lead > 100) score -= PST[3*BW*BH+bKing]*(32 - filling) >> 3; // white leads, drive black K to corner\r
- if(lead < -100) score += PST[3*BW*BH+wKing]*(32 - filling) >> 3; // black leads, drive white K to corner\r
+ 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
}\r
\r
# ifdef FORTRESS\r
if(filling < 128) {\r
int sq;\r
if((wLion = kylin[WHITE]) && (sq = p[wLion].pos) != ABSENT) {\r
- int anchor = sq - PST[5*BW*BH - 1 - sq];\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
}\r
if((bLion = kylin[BLACK]) && (sq = p[bLion].pos) != ABSENT) {\r
- int anchor = sq + PST[4*BW*BH + BH + sq];\r
+ int anchor = sq + PST[PST_ZONDIST + sq];\r
score -= (512 - Surround(WHITE, anchor, 0))*(128 - filling)*PST[p[bLion].pst + sq] >> 15;\r
}\r
}\r
\r
void GetLine(int root)\r
{\r
+\r
int i, c;\r
while(1) {\r
// wait for input, and read it until we have collected a complete line\r