Fix spurious promotion partners
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sat, 6 Feb 2016 09:21:21 +0000 (10:21 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sat, 6 Feb 2016 09:21:21 +0000 (10:21 +0100)
When defining a new promotion pairing through ^L the default partners
of L and +L must be made partnerless, or they would still promote to +L
or demote to L.

backend.c

index ffd9c44..b956f94 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -6050,7 +6050,11 @@ SetCharTableEsc (unsigned char *table, const char * map, char * escapes)
                     int p;
                     for(p=0; p<EmptySquare; p++) if(table[p] == partner[i]) break;
                     if(c == '^') table[i] = '+';
-                    if(p < EmptySquare) promoPartner[p] = i, promoPartner[i] = p; // marry them
+                    if(p < EmptySquare) {
+                        if(promoPartner[promoPartner[p]] == p) promoPartner[promoPartner[p]] = promoPartner[p]; // divorce old partners
+                        if(promoPartner[promoPartner[i]] == i) promoPartner[promoPartner[i]] = promoPartner[i];
+                        promoPartner[p] = i, promoPartner[i] = p; // and marry this couple
+                    }
                 } else if(c == '*') {
                     table[i] = partner[i];
                     promoPartner[i] = (i < BlackPawn ? WhiteTokin : BlackTokin); // promotes to Tokin