int Threshold = 800;\r
int Score;\r
int makruk;\r
+int prom;\r
char piecename[32], piecetype[32], blacktype[32];\r
+char selectedFairy[80];\r
char *inifile = INI_FILE;\r
\r
int Ticks, tlim, Setup, SetupQ;\r
\r
int GameHistory[1024];\r
-char HistoryBoards[1024][STATE], setupPosition[131];\r
+char HistoryBoards[1024][STATE], setupPosition[162];\r
int GamePtr, HistPtr;\r
\r
#define W while\r
of[256],\r
od[16]; /* 1st dir. in o[] per piece*/\r
\r
-signed char L,pl[17],\r
+signed char L,pl[32],\r
b[513], /* board: 16x8+dummy, + PST */\r
T[4104], /* hash translation table */\r
centr[32],\r
D(k,q,l,e,E,z,n) /* recursive minimax search, k=moving side, n=depth*/\r
int k,q,l,e,E,z,n; /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/\r
{ /* e=score, z=prev.dest; J,Z=hashkeys; return score*/\r
- int j,r,m,v,d,h,i,F,G,P,V,f=J,g=Z,C,s,flag,FF,*ps=sp;\r
+ int j,r,m,v,d,h,i,F,G,P,V,f=J,g=Z,C,s,flag,FF,*ps=sp,kk=S;\r
signed char t,p,u,x,y,X,Y,H,B;\r
struct _*a=A+(J+(k+S)*E&U-1); /* lookup pos. in hash table*/\r
*sp++=0;\r
if(flag&1+!t) /* mode (capt/nonc) allowed?*/\r
{if(t&&(t&16)==k)break; /* capture own */\r
i=w[t&15]+((t&192)>>sh); /* value of capt. piece t */\r
- if(i<0)m=I,d=98; /* K capture */\r
+ if(i<0&&(pl[t&31]<2||kk!=H&kk!=S||(kk=H,i=-i,0)))m=I,d=98;/* K capture, duple check */\r
if(m>=l&d>1)goto C; /* abort on fail high */\r
v=d-1?e:i-p; /*** MVV/LVA scoring if d=1**/\r
if(d-!t>1) /*** all captures if d=2 ***/\r
{v=centr[p]?b[x+257]-b[y+257]:0; /* center positional pts. */\r
if(!(G&S))b[FF]=b[G],v+=50; /* castling: put R & score */\r
b[G]=b[H]=b[x]=0;b[y]=u|32; /* do move, set non-virgin */\r
+ pl[t&31]-=!!t; /* updat victim piece count */\r
v-=w[p]>0|R<EG?0:20; /*** freeze K in mid-game ***/\r
if(p<3) /* pawns: */\r
{v-=9*((x-2&M||b[x-2]-u)+ /* structure, undefended */\r
}\r
if(z&S&&K-I) /* move pending: check legal*/\r
{if(v+I&&x==K&y==L) /* if move found */\r
- {Q=-e-i;O=F;LL=L;\r
- if(b[y]-u&15)b[y]-=PromPiece, /* under-promotion, correct */\r
+ {Q=-e-i;O=F;LL=L;prom=0;\r
+ if(b[y]-u&15)prom=b[y]-=PromPiece, /* under-promotion, correct */\r
J+=PromPiece; /* piece & invalidate hash */\r
a->D=99;a->V=0; /* lock game in hash as draw*/\r
R-=i/FAC; /*** total captd material ***/\r
v=m; /* (prevent fail-lows on */\r
} /* K-capt. replies) */\r
J=f;Z=g;\r
- SHAMAX( pl[k]+=!!t; )\r
+ SHAMAX( pl[k]+=!!t; ) pl[t&31]+=!!t;\r
b[G]=b[FF];b[FF]=b[y]=0;b[x]=u;b[H]=t; /* undo move,G can be dummy */\r
} /* if non-castling */\r
if(z&S&&Post&K==I&d>2&v>V&v<l){int *p=ps;char X,Y;\r
((b[G=r<0?x&~15:BW-1|x&112]^32)<33 /* no virgin R in corner G, */\r
||b[G^1]|b[G^2]|b[FF=y+v-r]) /* no 2 empty sq. next to R */\r
)t+=flag&4; /* fake capt. for nonsliding*/\r
- else F=y; /* enable e.p. */\r
+ else if(flag&64)t=flag&128?0:t,flag&=63;else F=y; /* enable e.p. */\r
if(s&&flag&8)t=0,flag^=flag>>4&15; /* hoppers go to next phase */\r
if(!(flag&S)) /* zig-zag piece? */\r
r=v,flag^=flag>>4&15; /* alternate vector & mode */\r
}\r
K=I;\r
cnt = D(s,-I,I,Q,O,LL|4*S,3);\r
+#ifdef SHATRANJ\r
+ if(pl[s]==1 && pl[16-s]==1) {\r
+ printf("1/2-1/2 {Insufficient mating material}\n");\r
+ return 4;\r
+ }\r
+ if(pl[s]<=1 && pl[16-s]>1) {\r
+ if (s == BLACK)\r
+ printf("0-1 {Bare King}\n");\r
+ else\r
+ printf("1-0 {Bare King}\n");\r
+ return 5;\r
+ }\r
+#else\r
if(cnt>-I+1 && K==0 && L==0) {\r
printf("1/2-1/2 {Stalemate}\n");\r
return 2;\r
}\r
+#endif\r
if(cnt==-I+1) {\r
if (s == WHITE)\r
printf("0-1 {Black mates}\n");\r
printf("1/2-1/2 {Draw by fifty move rule}\n");\r
return 4;\r
}\r
-#ifdef SHATRANJ\r
- if(pl[s]==1 && pl[16-s]==1) {\r
- printf("1/2-1/2 {Insufficient mating material}\n");\r
- return 4;\r
- }\r
- if(pl[s]<=1 && pl[16-s]>1) {\r
- if (s == BLACK)\r
- printf("0-1 {Bare King}\n");\r
- else\r
- printf("1-0 {Bare King}\n");\r
- return 5;\r
- }\r
-#endif\r
return 0;\r
}\r
\r
int i,j;\r
\r
for(i=0;i<16*BH;i++)b[i]=0;\r
+ for(i=0;i<32;i++)pl[i]=0;\r
K=BW;W(K--)\r
{b[K]=oo[K+16]+16;b[K+112]=oo[K];b[K+16]=18;b[K+96]=1; /* initial board setup*/\r
+ pl[oo[K+16]+16]++;pl[oo[K]]++;pl[18]++;pl[1]++;\r
L=8;W(L--)b[16*L+K+257]=(K-BW/2)*(K-BW/2)+(L-3.5)*(L-3.5); /* center-pts table */\r
} /*(in unused half b[])*/\r
Side = WHITE; Q=0; O=S;\r
HistoryBoards[s][BW*i+j] = b[16*i+j]|64*(16*i+j==O);\r
}\r
\r
-void PrintVariants()\r
+void PrintVariants(int combo)\r
{\r
- int i, j, count=0; char c, buf[80];\r
+ int i, j, count=0, total=0; char c, buf[80];\r
FILE *f;\r
\r
f = fopen(INI_FILE, "r");\r
while(fscanf(f, "Game: %s", buf) != 1 && c != EOF) \r
while((c = fgetc(f)) != EOF && c != '\n');\r
if(c == EOF) break;\r
- if(count++) printf(",");\r
- printf("%s", buf);\r
+ total++;\r
+ if(combo == (strstr(buf, "fairy/") != buf)) continue;\r
+ if(combo && count == 0) strcpy(selectedFairy, buf);\r
+ if(count++) printf(combo ? " /// " : ",");\r
+ printf("%s", combo ? buf+6 : buf);\r
} while(c != EOF);\r
\r
fclose(f);\r
+ if(!combo && total != count) printf("%sfairy", count ? "," : "");\r
}\r
\r
void PrintOptions()\r
printf("feature option=\"Resign Threshold -spin %d 200 1200\"\n", Threshold);\r
printf("feature option=\"Ini File -file %s\"\n", inifile);\r
printf("feature option=\"Multi-PV Margin -spin %d 0 1000\"\n", margin);\r
- printf("feature option=\"Playing Style ;-) -combo Brilliant /// *Brave /// Beautiful\"\n");\r
+ printf("feature option=\"Variant fairy selects -combo "); PrintVariants(1); printf("\"\n");\r
printf("feature option=\"Dummy Slider Example -slider 20 0 100\"\n");\r
- printf("feature option=\"Dummy String Example -file happy birthday!\"\n");\r
+ printf("feature option=\"Dummy String Example -string happy birthday!\"\n");\r
printf("feature option=\"Dummy Path Example -path .\"\n");\r
printf("feature option=\"Clear Hash -button\"\n");\r
printf("feature done=1\n");\r
\r
if(name != NULL)\r
{ /* search for game name in definition file */\r
+ if(!strcmp(name, "fairy")) name = selectedFairy;\r
while(fscanf(f, "Game: %s", buf)!=1 || strcmp(name, buf) ) {\r
while((c = fgetc(f)) != EOF && c != '\n');\r
count++;\r
printf("move ");\r
printf("%c%c%c%c",'a'+(K&15),'0'+BH-(K>>4),\r
'a'+(L&15),'0'+BH-(L>>4));\r
+ if(prom)printf("%c",piecename[prom&15]+'a'-1);\r
printf("\n");\r
m = GetTickCount() - Ticks;\r
\r
printf("feature memory=1\n");\r
printf("feature setboard=0 ping=1 done=0\n");\r
printf("feature variants=\"");\r
- PrintVariants();\r
+ PrintVariants(0);\r
printf("\"\n");\r
PrintOptions();\r
continue;\r
}\r
if (!strcmp(command, "white")) {\r
/* set white to move in current position */\r
+ if(Side == BLACK) Q = -Q;\r
Side = WHITE;\r
Computer = BLACK;\r
continue;\r
}\r
if (!strcmp(command, "black")) {\r
/* set blck to move in current position */\r
+ if(Side == WHITE) Q = -Q;\r
Side = BLACK;\r
Computer = WHITE;\r
continue;\r
}\r
if(sscanf(line+7, "Clear Hash") == 1) for(i=0; i<U; i++) A->K = 0;\r
if(sscanf(line+7, "MultiVariation Margin=%d", &margin) == 1) continue;\r
+ if(sscanf(line+7, "Variant fairy selects=%s", selectedFairy+6) == 1) continue;\r
continue;\r
}\r
if (!strcmp(command, "go")) {\r
InitGame();\r
if(Setup) {\r
for(i=0; i<128; i++) b[i] = setupPosition[i];\r
+ for(i=0; i<32; i++) pl[i] = setupPosition[i+130];\r
Side = setupPosition[128]; Q = SetupQ;\r
- pl[WHITE] = setupPosition[129];\r
- pl[BLACK] = setupPosition[130];\r
+ R = setupPosition[129];\r
}\r
for(i=0; i<=U; i++) A[i].D = A[i].K = 0; // clear hash table\r
for(nr=0; nr<GamePtr; nr++) {\r
if(m=='.') break;\r
if(m=='#') {\r
for(i=0; i<128; i++) b[i]=0;\r
+ for(i=0; i<32; i++) pl[i]=0;\r
Q=0; R=0; O=S;\r
pl[WHITE]=pl[BLACK]=0;\r
continue;\r
if(w[p]<0) { // Royal piece on original square: virgin
if(color==BLACK && m<0x10 && p==oo[m+16] ||\r
color==WHITE && m>0x6F && p==oo[m-0x70]) b[m] -= 32;
+ Q-=w[p]; // assume value was flipped to indicate royalty
+ if(pl[p+color])R-=w[p]/FAC; // capturable King, add to material
} else { Q+=w[p]; R+=w[p]/FAC; }
if((m==0x00 || m==BW-1 ) && color==BLACK && p==oo[m+16] ||\r
(m==0x70 || m==0x6F+BW) && color==WHITE && p==oo[m-0x70])\r
case 0: // undefined piece, ignore\r
break;\r
}\r
- pl[BLACK+WHITE-color]++;\r
+ pl[BLACK+WHITE-color]++;pl[p+color]++;\r
continue;\r
}\r
}\r
GamePtr = HistPtr = 0; Setup = 1; SetupQ = Q; // start anew\r
for(i=0; i<128; i++) setupPosition[i] = b[i]; // remember position\r
setupPosition[128] = Side;\r
- setupPosition[129] = pl[WHITE];\r
- setupPosition[130] = pl[BLACK];\r
+ setupPosition[129] = R;\r
+ for(i=0; i<32; i++) setupPosition[i+130] = pl[i];\r
continue;\r
}\r
/* command not recognized, assume input move */\r