char *name, *promoted;\r
int value;\r
signed char range[8];\r
+ int whiteKey, blackKey;\r
} PieceDesc;\r
\r
typedef struct {\r
#define board (rawBoard + 6*BW + 3)\r
#define dist (distance + BSIZE)\r
\r
-int LookUp(char *name, PieceDesc *list)\r
+PieceDesc *\r
+LookUp (char *name, PieceDesc *list)\r
{ // find piece of given name in list of descriptors\r
int i=0;\r
while(list->name && strcmp(name, list->name)) i++, list++;\r
- return (list->name == NULL ? -1 : i);\r
+ return (list->name == NULL ? NULL : list);\r
}\r
\r
void\r
}\r
\r
int\r
-AddPiece (int stm, int n, PieceDesc *list)\r
+AddPiece (int stm, PieceDesc *list)\r
{\r
- int i, j;\r
+ int i, j, *key;\r
for(i=stm+2; i<=last[stm]; i += 2) {\r
- if(p[i].value < 10*list[n].value || p[i].value == 10*list[n].value && (p[i].promo < 0)) break;\r
+ if(p[i].value < 10*list->value || p[i].value == 10*list->value && (p[i].promo < 0)) break;\r
}\r
last[stm] += 2;\r
for(j=last[stm]; j>i; j-= 2) p[j] = p[j-2];\r
- p[i].value = 10*list[n].value;\r
- for(j=0; j<8; j++) p[i].range[j] = list[n].range[j^4*(WHITE-stm)];\r
+ p[i].value = 10*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
}\r
+ key = (stm == WHITE ? &list->whiteKey : &list->blackKey);\r
+ if(!*key) *key = ~(myRandom()*myRandom());\r
+ p[i].pieceKey = *key;\r
p[i].promoFlag = 0;\r
for(j=stm+2; j<= last[stm]; j+=2) {\r
if(p[j].promo >= i) p[j].promo += 2;\r
void\r
SetUp(char *array, PieceDesc *list)\r
{\r
- int i, j, k, k2, n, m, nr, color;\r
+ int i, j, n, m, nr, color;\r
char c, *q, name[3];\r
+ PieceDesc *p1, *p2;\r
last[WHITE] = 1; last[BLACK] = 0;\r
for(i=0; ; i++) {\r
//printf("next rank: %s\n", array);\r
name[0] += 'A' - 'a';\r
if(name[1]) name[1] += 'A' - 'a';\r
} else color = WHITE;\r
- k = LookUp(name, list);\r
- n = AddPiece(color, k, list);\r
+ p1 = LookUp(name, list);\r
+ n = AddPiece(color, p1);\r
p[n].pos = j;\r
- if(list[k].promoted[0]) {\r
- k2 = LookUp(list[k].promoted, list);\r
- m = AddPiece(color, k2, list);\r
+ if(p1->promoted[0]) {\r
+ p2 = LookUp(p1->promoted, list);\r
+ m = AddPiece(color, p2);\r
if(m <= n) n += 2;\r
p[n].promo = m;\r
- p[n].promoFlag = IsUpwardCompatible(list[k2].range, list[k].range) * DONT_DEFER + CAN_PROMOTE;\r
- if(Forward(list[k].range)) p[n].promoFlag |= LAST_RANK; // Pieces that only move forward can't defer on last rank\r
- if(!strcmp(list[k].name, "N")) p[n].promoFlag |= CANT_DEFER; // Knights can't defer on last 2 ranks\r
+ p[n].promoFlag = IsUpwardCompatible(p2->range, p1->range) * DONT_DEFER + CAN_PROMOTE;\r
+ if(Forward(p1->range)) p[n].promoFlag |= LAST_RANK; // Pieces that only move forward can't defer on last rank\r
+ if(!strcmp(p1->name, "N")) p[n].promoFlag |= CANT_DEFER; // Knights can't defer on last 2 ranks\r
p[n].promoFlag &= n&1 ? P_WHITE : P_BLACK;\r
p[m].promo = -1;\r
p[m].pos = ABSENT;\r
\r
// hash key tables\r
for(i=0; i<BSIZE; i++) squareKey[i] = ~(myRandom()*myRandom());\r
- for(i=0; i<NPIECES; i++) p[i].pieceKey = ~(myRandom()*myRandom());\r
\r
// board edge\r
for(i=0; i<BSIZE + 11*BW + 6; i++) rawBoard[i] = EDGE;\r
{\r
SetUp(chuArray, chuPieces);\r
sup0 = sup1 = sup2 = ABSENT;\r
- rootEval = 0;\r
+ rootEval = hashKeyH = hashKeyL = 0;\r
return WHITE;\r
}\r
\r