Send setup command to GUI
[fairymax.git] / fairymax.c
index 0c1fc81..be12a63 100644 (file)
@@ -18,7 +18,7 @@
      /*****************************************************************/\r
 \r
 #define MULTIPATH\r
-#define VERSION "4.8O"\r
+#define VERSION "4.8P"\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -373,6 +373,8 @@ InitGame()
  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
+  if(w[oo[K+16]+16] == -1)pl[oo[K+16]+16]=1;\r
+  if(w[oo[K]] == -1)pl[oo[K]]=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
@@ -433,7 +435,7 @@ void PrintOptions()
                                          \r
 int LoadGame(char *name)\r
 {\r
-        int i, j, count=0; char c, buf[80];\r
+        int i, j, ptc, count=0; char c, buf[80], pieceToChar[80];\r
         static int currentVariant;\r
         FILE *f;\r
 \r
@@ -448,7 +450,7 @@ int LoadGame(char *name)
         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((ptc=fscanf(f, "Game: %s # %s", buf, pieceToChar))==0 || strcmp(name, buf) ) {\r
                while((c = fgetc(f)) != EOF && c != '\n');\r
                count++;\r
                if(c == EOF) {\r
@@ -486,6 +488,14 @@ int LoadGame(char *name)
         fclose(f);\r
        sh = w[7] < 250 ? 3 : 0;\r
        makruk = w[7]==181 ? 64 : 0; // w[7] is used as kludge to enable makruk promotions\r
+        if(name == selectedFairy) {\r
+            printf(ptc == 1 ? "setup " : "setup (%s) ", pieceToChar); // setup board in GUI\r
+            for(i=0; i<BW; i++) printf("%c", piecename[oo[i+16]]+'`'); printf("/");\r
+            for(i=0; i<BW; i++) printf("%c", piecename[2]+'`'); printf("/");\r
+            for(i=2; i<BH-2; i++) printf("%d/", BW);\r
+            for(i=0; i<BW; i++) printf("%c", piecename[1]+'@'); printf("/");\r
+            for(i=0; i<BW; i++) printf("%c", piecename[oo[i]]+'@'); printf(" w KQkq - 0 1\n");\r
+        }\r
 }\r
 \r
 int main(int argc, char **argv)\r
@@ -813,6 +823,7 @@ int main(int argc, char **argv)
                                             break;\r
                                         }\r
                                         pl[BLACK+WHITE-color]++;pl[p+color]++;\r
+                                        if(w[p+color] == -1)pl[p+color]=1; // fake we have one if value = -1, to thwart extinction condition\r
                                         continue;\r
                                 }\r
                         }\r