From 39368b47d7825d53d1341be916fcc74a6dbe7a2d Mon Sep 17 00:00:00 2001
From: H.G. Muller <h.g.muller@hccnet.nl>
Date: Fri, 15 Jan 2010 09:32:25 +0100
Subject: [PATCH] Allow different white and black pieces to use same name

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 |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

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