Fix type-in of hit-and-run captures
[xboard.git] / backend.c
index ffd9c44..a4f7852 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5556,6 +5556,7 @@ ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fro
         *toX = currentMoveString[2] - AAA;
         *toY = currentMoveString[3] - ONE;
        *promoChar = currentMoveString[4];
+       if(*promoChar == ';') *promoChar = NULLCHAR;
         if (*fromX < BOARD_LEFT || *fromX >= BOARD_RGHT || *fromY < 0 || *fromY >= BOARD_HEIGHT ||
             *toX < BOARD_LEFT || *toX >= BOARD_RGHT || *toY < 0 || *toY >= BOARD_HEIGHT) {
     if (appData.debugMode) {
@@ -6003,7 +6004,7 @@ ptclen (const char *s, char *escapes)
 {
     int n = 0;
     if(!*escapes) return strlen(s);
-    while(*s) n += (*s != '/' && *s != '-' && *s != '^' && *s != '*' && !strchr(escapes, *s)), s++;
+    while(*s) n += (*s != '/' && *s != '-' && *s != '^' && *s != '*' && !strchr(escapes, *s)) - 2*(*s == '='), s++;
     return n;
 }
 
@@ -6027,6 +6028,7 @@ SetCharTableEsc (unsigned char *table, const char * map, char * escapes)
             table[i+offs] = map[j++];
             if(p = strchr(escapes, map[j])) j++, table[i+offs] += 64*(p - escapes + 1);
             if(c) partner[i+offs] = table[i+offs], table[i+offs] = c;
+            if(*escapes && map[j] == '=') pieceNickName[i+offs] = map[++j], j++;
         }
         table[(int) WhiteKing]  = map[j++];
         for( ii=offs=0; ii<NrPieces/2-1; ii++ ) {
@@ -6037,6 +6039,7 @@ SetCharTableEsc (unsigned char *table, const char * map, char * escapes)
             table[i+offs] = map[j++];
             if(p = strchr(escapes, map[j])) j++, table[i+offs] += 64*(p - escapes + 1);
             if(c) partner[i+offs] = table[i+offs], table[i+offs] = c;
+            if(*escapes && map[j] == '=') pieceNickName[i+offs] = map[++j], j++;
         }
         table[(int) BlackKing]  = map[j++];
 
@@ -6050,7 +6053,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
@@ -13103,7 +13110,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList)
            return FALSE;
          }
          CopyBoard(boards[0], initial_position);
-         if(*engineVariant) // [HGM] for now, assume FEN in engine-defined variant game is default initial position
+         if(*engineVariant || gameInfo.variant == VariantFairy) // [HGM] for now, assume FEN in engine-defined variant game is default initial position
            CopyBoard(initialPosition, initial_position);
          if (blackPlaysFirst) {
            currentMove = forwardMostMove = backwardMostMove = 1;
@@ -16273,7 +16280,7 @@ PrintPosition (FILE *fp, int move)
     for (i = BOARD_HEIGHT - 1; i >= 0; i--) {
         for (j = BOARD_LEFT; j < BOARD_RGHT; j++) {
            char c = PieceToChar(boards[move][i][j]);
-           fputc(c == 'x' ? '.' : c, fp);
+           fputc(c == '?' ? '.' : c, fp);
             fputc(j == BOARD_RGHT - 1 ? '\n' : ' ', fp);
        }
     }