Allow RxK notation for entering castling
[fairymax.git] / fairymax.c
index 85783a1..7fb3cad 100644 (file)
@@ -93,7 +93,7 @@ int Resign;
 int Threshold = 800;\r
 int Score;\r
 int makruk;\r
-int prom, pm;\r
+int prom, pm, gating;\r
 char piecename[32], piecetype[32], blacktype[32];\r
 char selectedFairy[80];\r
 char *inifile = INI_FILE;\r
@@ -389,6 +389,7 @@ InitGame()
  R -= 2*(-k/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
+ if(gating) pl[13] = pl[15] = pl[29] = pl[31] = 1, R += 2*(w[6]/FAC + w[8]/FAC);\r
 }\r
 \r
 void CopyBoard(int s)\r
@@ -454,9 +455,11 @@ int LoadGame(char *name)
         if(fscanf(f, "version 4.8(%c)", &c)!=1 || c != 'w')\r
         { printf("telluser incompatible fmax.ini file\n"); exit(0); }\r
 \r
+        gating = 0;
         if(name != NULL)\r
         {  /* search for game name in definition file */\r
-           if(!strcmp(name, "fairy")) name = selectedFairy;\r
+           if(!strcmp(name, "fairy")) name = selectedFairy;
+           gating = !strcmp(name, "seirawan");\r
            while((ptc=fscanf(f, "Game: %s # %s", buf, pieceToChar))==0 || strcmp(name, buf) ) {\r
                while((c = fgetc(f)) != EOF && c != '\n');\r
                count++;\r
@@ -784,7 +787,6 @@ int main(int argc, char **argv)
                         sscanf(line, "variant %s", command);\r
                         LoadGame(command);\r
                         InitGame(); Setup = 0;\r
-                        if(strstr(command,"seirawan")) pl[13] = pl[15] = pl[29] = pl[31] = 1;\r
                        continue;\r
                }\r
                 if (!strcmp(command, "edit")) {\r
@@ -857,14 +859,18 @@ int main(int argc, char **argv)
                 if (m)\r
                         /* doesn't have move syntax */\r
                        printf("Error (unknown command): %s\n", command);\r
-                else if(D(Side,-I,I,Q,O,LL|S,3)!=I) {\r
+                else { int i=K;\r
+                    if(b[L] && (b[L]&16) == Side && w[b[L]&15] < 0) // capture own King: castling\r
+                    { K = L; L = i>L ? i-1 : i+2; }\r
+                    if(D(Side,-I,I,Q,O,LL|S,3)!=I) {\r
                         /* did have move syntax, but illegal move */\r
                         printf("Illegal move:%s\n", line);\r
-                } else {  /* legal move, perform it */\r
+                    } else {  /* legal move, perform it */\r
                         GameHistory[GamePtr++] = PACK_MOVE;\r
                         Side ^= BLACK^WHITE;\r
                         CopyBoard(HistPtr=HistPtr+1&1023);\r
                         if(PrintResult(Side)) Computer = EMPTY;\r
+                   }\r
                }\r
        }\r
 }\r