Allow different white and black pieces to use same name
authorH.G. Muller <h.g.muller@hccnet.nl>
Fri, 15 Jan 2010 08:32:25 +0000 (09:32 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Fri, 15 Jan 2010 08:32:25 +0000 (09:32 +0100)
White and black pieces must sometimes be programmed separately, because
they have asymmetric moves (e.g. Pawns), but when they are each other's
mirror imge, we want them to go by the same name. To allow that, the
first piece of any name is now used for white, the last for black.

fairymax.c

index 15e4f15..c166ee1 100644 (file)
@@ -92,7 +92,7 @@ int GameNr;
 int Resign;\r
 int Threshold = 800;\r
 int Score;\r
-char piecename[32], piecetype[32];\r
+char piecename[32], piecetype[32], blacktype[32];\r
 char *inifile = INI_FILE;\r
 \r
 int Ticks, tlim, Setup, SetupQ;\r
@@ -452,14 +452,15 @@ int LoadGame(char *name)
         for(i=0; i<BW; i++) fscanf(f, "%d", oo+i+16);\r
         for(i= 0; i<=U; i++)\r
             A[i].K = A[i].D = A[i].X = A[i].Y = A[i].F = 0; /* clear hash */\r
-        for(i=0; i<32; i++) piecetype[i] = 0;\r
+        for(i=0; i<32; i++) piecetype[i] = blacktype[i] = 0;\r
 \r
         i=0; j=-1; c=0;\r
         while(fscanf(f, "%d,%x", o+j, of+j)==2 ||\r
                                       fscanf(f,"%c:%d",&c, w+i+1)==2)\r
         {   if(c)\r
             { od[++i]=j; centr[i] = c>='a';\r
-              piecetype[c&31]=i; piecename[i]=c&31;\r
+              blacktype[c&31]=i; piecename[i]=c&31;\r
+              if(piecetype[c&31]==0) piecetype[c&31]=i; // only first\r
             }\r
             j++; o[j]=0;\r
             /* printf("# c='%c' i=%d od[i]=%d j=%d (%3d,%8x)\n",c?c:' ',i,od[i],j,o[j-1],of[j-1]); /**/\r
@@ -765,7 +766,7 @@ int main(int argc, char **argv)
                                     && line[1] >= 'a' && line[1] <= 'a'+BW-1\r
                                     && line[2] >= '1' && line[2] <= '0'+BH) {\r
                                         m = line[1]-16*line[2]+799;\r
-                                        switch(p = piecetype[line[0]&31])\r
+                                        switch(p = (color == WHITE ? piecetype : blacktype)[line[0]&31])\r
                                         {\r
                                         case 1:\r
                                         case 2:\r
@@ -810,7 +811,7 @@ int main(int argc, char **argv)
                 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 - piecetype[line[4]&31];\r
+                PromPiece = 7 - (Side == WHITE ? piecetype : blacktype)[line[4]&31];\r
                    if(PromPiece == 7) PromPiece = 0;\r
                 {char *c=line; K=c[0]-16*c[1]+799;L=c[2]-16*c[3]+799; }\r
                 if (m)\r