Allow different default promo piece for black and white
[fairymax.git] / fairymax.c
index 2c16397..5b2e98a 100644 (file)
@@ -93,7 +93,7 @@ int Resign;
 int Threshold = 800;\r
 int Score;\r
 int makruk;\r
-int prom;\r
+int prom, pm;\r
 char piecename[32], piecetype[32], blacktype[32];\r
 char selectedFairy[80];\r
 char *inifile = INI_FILE;\r
@@ -195,7 +195,7 @@ int k,q,l,e,E,z,n;      /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/
                (x+2&M||b[x+2]-u)               /*        squares plus bias */\r
               +(w[b[x^16]&15]<0))              /*** cling to magnetic K ***/\r
               +(R-76>>2);                      /* end-game Pawn-push bonus */\r
-         b[y]+=V=y+r+1&S?647-p:2*(u&y+16&32);  /* upgrade P or convert to Q*/\r
+         b[y]+=V=y+r+1&S?647-p|pm:2*(u&y+16&32);/*upgrade P or convert to Q*/\r
          if(V&makruk)b[y]=u|7,V=480;           /* Makruk promotion on 6th  */\r
          V>>=sh;                               /* for Shatranj promo to F  */\r
          i+=V;                                 /* promotion / passer bonus */\r
@@ -378,6 +378,7 @@ InitGame()
  Fifty = 0; R = 0;\r
  for(i=0; i<BW; i++) if(i!=3) R += (w[oo[i]]/FAC) + (w[oo[i+16]]/FAC);\r
  UnderProm = -1; pl[WHITE] = pl[BLACK] = 2*BW;\r
+ pm = !pl[BLACK+7] && pl[BLACK+9] && pl[WHITE+7] ? 2 : 0; // Unlike white, black has no 'Q', so promote to 9, which he does have.\r
 }\r
 \r
 void CopyBoard(int s)\r
@@ -825,9 +826,9 @@ int main(int argc, char **argv)
                 /* command not recognized, assume input move */\r
                 m = line[0]<'a' | line[0]>='a'+BW | line[1]<'1' | line[1]>='1'+BH |\r
                     line[2]<'a' | line[2]>='a'+BW | line[3]<'1' | line[3]>='1'+BH;\r
-                if(line[4] == '\n') line[4] = piecename[7];\r
-                PromPiece = 7 - (Side == WHITE ? piecetype : blacktype)[line[4]&31];\r
-                   if(PromPiece == 7) PromPiece = 0;\r
+                if(line[4] == '\n') line[4] = 0;\r
+                PromPiece = (Side == WHITE ? piecetype : blacktype)[line[4]&31];\r
+                if(PromPiece) PromPiece = (Side == WHITE ? 7 : 7+pm) - PromPiece;\r
                 {char *c=line; K=c[0]-16*c[1]+799;L=c[2]-16*c[3]+799; }\r
                 if (m)\r
                         /* doesn't have move syntax */\r