Remove promotion-piece encoding from ChessMove type
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 4 Oct 2010 07:32:18 +0000 (09:32 +0200)
committerArun Persaud <arun@nubati.net>
Tue, 5 Oct 2010 02:35:12 +0000 (19:35 -0700)
The shizophrenic way to indcate promotion pieces in the XBoard code
(sometimes using a promoChar, at other times relying on moveType) was
cured by combining all promotion move types (such as WhitePromotionRook)
into a single one (WhitePromotion), and relying on promoChar to specify
the piece. This solves the problem of promoting to new piece types in
variants, which formerly also required addition of new move types.

In Shogi the '+' character is now consistently used to indicate
promotions (and recognized in ApplyMove), rather than 'q' or
PieeToChar(BlackQueen), as the latter did not work in minivariants where
the Queen (representng the Lance) did not partcipate.

backend.c
common.h
moves.c
parser.c
parser.l

index 01dd29f..2a6e2e6 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -4579,20 +4579,8 @@ SendMoveToICS(moveType, fromX, fromY, toX, toY, promoChar)
       case BlackNonPromotion:
         sprintf(user_move, "%c%c%c%c=\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY);
         break;
-      case WhitePromotionQueen:
-      case BlackPromotionQueen:
-      case WhitePromotionRook:
-      case BlackPromotionRook:
-      case WhitePromotionBishop:
-      case BlackPromotionBishop:
-      case WhitePromotionKnight:
-      case BlackPromotionKnight:
-      case WhitePromotionKing:
-      case BlackPromotionKing:
-      case WhitePromotionChancellor:
-      case BlackPromotionChancellor:
-      case WhitePromotionArchbishop:
-      case BlackPromotionArchbishop:
+      case WhitePromotion:
+      case BlackPromotion:
         if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
             sprintf(user_move, "%c%c%c%c=%c\n",
                 AAA + fromX, ONE + fromY, AAA + toX, ONE + toY,
@@ -4793,20 +4781,8 @@ ParseOneMove(move, moveNum, moveType, fromX, fromY, toX, toY, promoChar)
     *moveType = yylexstr(moveNum, move, yy_textstr, sizeof yy_textstr);
 
     switch (*moveType) {
-      case WhitePromotionChancellor:
-      case BlackPromotionChancellor:
-      case WhitePromotionArchbishop:
-      case BlackPromotionArchbishop:
-      case WhitePromotionQueen:
-      case BlackPromotionQueen:
-      case WhitePromotionRook:
-      case BlackPromotionRook:
-      case WhitePromotionBishop:
-      case BlackPromotionBishop:
-      case WhitePromotionKnight:
-      case BlackPromotionKnight:
-      case WhitePromotionKing:
-      case BlackPromotionKing:
+      case WhitePromotion:
+      case BlackPromotion:
       case WhiteNonPromotion:
       case BlackNonPromotion:
       case NormalMove:
@@ -5649,8 +5625,7 @@ HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice)
     if(appData.testLegality && !premove) {
        moveType = LegalityTest(boards[currentMove], PosFlags(currentMove),
                        fromY, fromX, toY, toX, NULLCHAR);
-       if(moveType != WhitePromotionQueen && moveType  != BlackPromotionQueen &&
-          moveType != WhitePromotionKnight && moveType != BlackPromotionKnight)
+       if(moveType != WhitePromotion && moveType  != BlackPromotion)
            return FALSE;
     }
 
@@ -5803,8 +5778,7 @@ OnlyMove(int *x, int *y, Boolean captures) {
     Disambiguate(boards[currentMove], PosFlags(currentMove), &cl);
     if( cl.kind == NormalMove ||
        cl.kind == AmbiguousMove && captures && cl.captures == 1 ||
-       cl.kind == WhitePromotionQueen || cl.kind == BlackPromotionQueen ||
-       cl.kind == WhitePromotionKnight || cl.kind == BlackPromotionKnight ||
+       cl.kind == WhitePromotion || cl.kind == BlackPromotion ||
        cl.kind == WhiteCapturesEnPassant || cl.kind == BlackCapturesEnPassant) {
       fromX = cl.ff;
       fromY = cl.rf;
@@ -5822,8 +5796,7 @@ OnlyMove(int *x, int *y, Boolean captures) {
     Disambiguate(boards[currentMove], PosFlags(currentMove), &cl);
     if( cl.kind == NormalMove ||
        cl.kind == AmbiguousMove && captures && cl.captures == 1 ||
-       cl.kind == WhitePromotionQueen || cl.kind == BlackPromotionQueen ||
-       cl.kind == WhitePromotionKnight || cl.kind == BlackPromotionKnight ||
+       cl.kind == WhitePromotion || cl.kind == BlackPromotion ||
        cl.kind == WhiteCapturesEnPassant || cl.kind == BlackCapturesEnPassant) {
       fromX = cl.ff;
       fromY = cl.rf;
@@ -6034,7 +6007,7 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar)
     /* [HGM] <popupFix> kludge to avoid having to know the exact promotion
        move type in caller when we know the move is a legal promotion */
     if(moveType == NormalMove && promoChar)
-        moveType = PromoCharToMoveType(WhiteOnMove(currentMove), promoChar);
+        moveType = WhiteOnMove(currentMove) ? WhitePromotion : BlackPromotion;
 
     /* [HGM] <popupFix> The following if has been moved here from
        UserMoveEvent(). Because it seemed to belong here (why not allow
@@ -8116,20 +8089,8 @@ ParseGameHistory(game)
     fprintf(debugFP, "board L=%d, R=%d, H=%d, holdings=%d\n", BOARD_LEFT, BOARD_RGHT, BOARD_HEIGHT, gameInfo.holdingsWidth);
     setbuf(debugFP, NULL);
   }
-          case WhitePromotionChancellor:
-          case BlackPromotionChancellor:
-          case WhitePromotionArchbishop:
-          case BlackPromotionArchbishop:
-         case WhitePromotionQueen:
-         case BlackPromotionQueen:
-         case WhitePromotionRook:
-         case BlackPromotionRook:
-         case WhitePromotionBishop:
-         case BlackPromotionBishop:
-         case WhitePromotionKnight:
-         case BlackPromotionKnight:
-         case WhitePromotionKing:
-         case BlackPromotionKing:
+         case WhitePromotion:
+         case BlackPromotion:
          case WhiteNonPromotion:
          case BlackNonPromotion:
          case NormalMove:
@@ -8474,10 +8435,6 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board)
        board[toY][toX] = board[fromY][fromX];
        board[fromY][fromX] = EmptySquare;
     }
-
-    /* [HGM] now we promote for Shogi, if needed */
-    if(gameInfo.variant == VariantShogi && promoChar == 'q')
-        board[toY][toX] = (ChessSquare) (PROMOTED piece);
   }
 
     if (gameInfo.holdingsWidth != 0) {
@@ -8553,11 +8510,12 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board)
        board[toY][toX] = EmptySquare;
       }
     }
-    if(gameInfo.variant == VariantShogi && promoChar != NULLCHAR && promoChar != '=') {
-        /* [HGM] Shogi promotions */
+    if(promoChar == '+') {
+        /* [HGM] Shogi-style promotions, to piece implied by original (Might overwrite orinary Pawn promotion) */
         board[toY][toX] = (ChessSquare) (PROMOTED piece);
+    } else if(!appData.testLegality) { // without legality testing, unconditionally believe promoChar
+        board[toY][toX] = CharToPiece(promoChar);
     }
-
     if((gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) 
                && promoChar != NULLCHAR && gameInfo.holdingsSize) { 
        // [HGM] superchess: take promotion piece out of holdings
@@ -9591,22 +9549,8 @@ LoadGameOneMove(readAhead)
 
       case WhiteCapturesEnPassant:
       case BlackCapturesEnPassant:
-      case WhitePromotionChancellor:
-      case BlackPromotionChancellor:
-      case WhitePromotionArchbishop:
-      case BlackPromotionArchbishop:
-      case WhitePromotionCentaur:
-      case BlackPromotionCentaur:
-      case WhitePromotionQueen:
-      case BlackPromotionQueen:
-      case WhitePromotionRook:
-      case BlackPromotionRook:
-      case WhitePromotionBishop:
-      case BlackPromotionBishop:
-      case WhitePromotionKnight:
-      case BlackPromotionKnight:
-      case WhitePromotionKing:
-      case BlackPromotionKing:
+      case WhitePromotion:
+      case BlackPromotion:
       case WhiteNonPromotion:
       case BlackNonPromotion:
       case NormalMove:
index bc9d997..4b31719 100644 (file)
--- a/common.h
+++ b/common.h
@@ -256,12 +256,8 @@ typedef enum {
     BlackKingSideCastle, BlackQueenSideCastle,
     BlackKingSideCastleWild, BlackQueenSideCastleWild,
     BlackHSideCastleFR, BlackASideCastleFR, 
-    WhitePromotionKnight, WhitePromotionBishop,
-    WhitePromotionRook, WhitePromotionQueen, WhitePromotionKing, WhiteNonPromotion,
-    WhitePromotionChancellor, WhitePromotionArchbishop, WhitePromotionCentaur,
-    BlackPromotionKnight, BlackPromotionBishop,
-    BlackPromotionRook, BlackPromotionQueen, BlackPromotionKing, BlackNonPromotion,
-    BlackPromotionChancellor, BlackPromotionArchbishop, BlackPromotionCentaur,
+    WhitePromotion, WhiteNonPromotion,
+    BlackPromotion, BlackNonPromotion,
     WhiteCapturesEnPassant, BlackCapturesEnPassant,
     WhiteDrop, BlackDrop, 
     NormalMove, AmbiguousMove, IllegalMove, ImpossibleMove,
diff --git a/moves.c b/moves.c
index 2e8d672..56bd1da 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -97,47 +97,6 @@ int SameColor(piece1, piece2)
             (int) piece2 <  (int) EmptySquare);
 }
 
-ChessSquare PromoPiece(moveType)
-     ChessMove moveType;
-{
-    switch (moveType) {
-      default:
-       return EmptySquare;
-      case WhitePromotionQueen:
-       return WhiteQueen;
-      case BlackPromotionQueen:
-       return BlackQueen;
-      case WhitePromotionRook:
-       return WhiteRook;
-      case BlackPromotionRook:
-       return BlackRook;
-      case WhitePromotionBishop:
-       return WhiteBishop;
-      case BlackPromotionBishop:
-       return BlackBishop;
-      case WhitePromotionKnight:
-       return WhiteKnight;
-      case BlackPromotionKnight:
-       return BlackKnight;
-      case WhitePromotionKing:
-       return WhiteKing;
-      case BlackPromotionKing:
-       return BlackKing;
-      case WhitePromotionChancellor:
-        return WhiteMarshall;
-      case BlackPromotionChancellor:
-        return BlackMarshall;
-      case WhitePromotionArchbishop:
-        return WhiteAngel;
-      case BlackPromotionArchbishop:
-        return BlackAngel;
-      case WhitePromotionCentaur:
-        return WhiteSilver;
-      case BlackPromotionCentaur:
-        return BlackSilver;
-    }
-}
-
 char pieceToChar[] = {
                         'P', 'N', 'B', 'R', 'Q', 'F', 'E', 'A', 'C', 'W', 'M', 
                         'O', 'H', 'I', 'J', 'G', 'D', 'V', 'L', 'S', 'U', 'K',
@@ -174,54 +133,6 @@ ChessSquare CharToPiece(c)
      return EmptySquare;
 }
 
-ChessMove PromoCharToMoveType(whiteOnMove, promoChar)
-     int whiteOnMove;
-     int promoChar;
-{      /* [HGM] made dependent on CharToPiece to alow alternate piece letters */
-       ChessSquare piece = CharToPiece(whiteOnMove ? ToUpper(promoChar) : ToLower(promoChar) );
-
-       if(promoChar == '=') return whiteOnMove ? WhiteNonPromotion : BlackNonPromotion;
-       if(promoChar == NULLCHAR) return NormalMove;
-
-       switch(piece) {
-               case WhiteQueen:
-                       return WhitePromotionQueen;
-               case WhiteRook:
-                       return WhitePromotionRook;
-               case WhiteBishop:
-                       return WhitePromotionBishop;
-               case WhiteKnight:
-                       return WhitePromotionKnight;
-               case WhiteKing:
-                       return WhitePromotionKing;
-               case WhiteAngel:
-                       return WhitePromotionArchbishop;
-               case WhiteMarshall:
-                       return WhitePromotionChancellor;
-               case WhiteSilver:
-                       return WhitePromotionCentaur;
-               case BlackQueen:
-                       return BlackPromotionQueen;
-               case BlackRook:
-                       return BlackPromotionRook;
-               case BlackBishop:
-                       return BlackPromotionBishop;
-               case BlackKnight:
-                       return BlackPromotionKnight;
-               case BlackKing:
-                       return BlackPromotionKing;
-               case BlackAngel:
-                       return BlackPromotionArchbishop;
-               case BlackMarshall:
-                       return BlackPromotionChancellor;
-               case BlackSilver:
-                       return BlackPromotionCentaur;
-               default:
-                       // not all promotion implemented yet! Take Queen for those we don't know.
-                       return (whiteOnMove ? WhitePromotionQueen : BlackPromotionQueen);
-       }
-}
-
 void CopyBoard(to, from)
      Board to, from;
 {
@@ -310,7 +221,7 @@ void GenPseudoLegal(board, flags, callback, closure)
               }
               if (rf < BOARD_HEIGHT-1 && board[rf + 1][ff] == EmptySquare) {
                  callback(board, flags,
-                          rf >= BOARD_HEIGHT-1-promoRank ? WhitePromotionQueen : NormalMove,
+                          rf >= BOARD_HEIGHT-1-promoRank ? WhitePromotion : NormalMove,
                           rf, ff, rf + 1, ff, closure);
              }
              if (rf == 1 && board[2][ff] == EmptySquare &&
@@ -325,7 +236,7 @@ void GenPseudoLegal(board, flags, callback, closure)
                      ((flags & F_KRIEGSPIEL_CAPTURE) ||
                       BlackPiece(board[rf + 1][ff + s]))) {
                      callback(board, flags, 
-                              rf >= BOARD_HEIGHT-1-promoRank ? WhitePromotionQueen : NormalMove,
+                              rf >= BOARD_HEIGHT-1-promoRank ? WhitePromotion : NormalMove,
                               rf, ff, rf + 1, ff + s, closure);
                  }
                  if (rf == BOARD_HEIGHT-4) {
@@ -360,7 +271,7 @@ void GenPseudoLegal(board, flags, callback, closure)
               }
              if (rf > 0 && board[rf - 1][ff] == EmptySquare) {
                  callback(board, flags, 
-                          rf <= promoRank ? BlackPromotionQueen : NormalMove,
+                          rf <= promoRank ? BlackPromotion : NormalMove,
                           rf, ff, rf - 1, ff, closure);
              }
              if (rf == BOARD_HEIGHT-2 && board[BOARD_HEIGHT-3][ff] == EmptySquare &&
@@ -375,7 +286,7 @@ void GenPseudoLegal(board, flags, callback, closure)
                      ((flags & F_KRIEGSPIEL_CAPTURE) ||
                       WhitePiece(board[rf - 1][ff + s]))) {
                      callback(board, flags, 
-                              rf <= promoRank ? BlackPromotionQueen : NormalMove,
+                              rf <= promoRank ? BlackPromotion : NormalMove,
                               rf, ff, rf - 1, ff + s, closure);
                  }
                  if (rf == 3) {
@@ -1116,24 +1027,24 @@ ChessMove LegalityTest(board, flags, rf, ff, rt, ft, promoChar)
                && cl.kind != WhiteCapturesEnPassant && cl.kind != BlackCapturesEnPassant)
        return(IllegalMove); // [HGM] losers: if there are legal captures, non-capts are illegal
 
+    if(promoChar == 'x') promoChar = NULLCHAR; // [HGM] is this ever the case?
     if(gameInfo.variant == VariantShogi) {
         /* [HGM] Shogi promotions. '=' means defer */
         if(rf != DROP_RANK && cl.kind == NormalMove) {
             ChessSquare piece = board[rf][ff];
 
             if(promoChar == PieceToChar(BlackQueen)) promoChar = NULLCHAR; /* [HGM] Kludge */
-            if(promoChar != NULLCHAR && promoChar != 'x' &&
-               promoChar != '+' && promoChar != '=' &&
+            if(promoChar != NULLCHAR && promoChar != '+' && promoChar != '=' &&
                ToUpper(PieceToChar(PROMOTED piece)) != ToUpper(promoChar) )
                     cl.kind = IllegalMove;
             else if(flags & F_WHITE_ON_MOVE) {
                 if( (int) piece < (int) WhiteWazir &&
-                     (rf >= BOARD_HEIGHT-(BOARD_HEIGHT/3) || rt >= BOARD_HEIGHT-(BOARD_HEIGHT/3)) ) {
+                     (rf >= BOARD_HEIGHT*2/3 || rt >= BOARD_HEIGHT*2/3) ) {
                     if( (piece == WhitePawn || piece == WhiteQueen) && rt > BOARD_HEIGHT-2 ||
                          piece == WhiteKnight && rt > BOARD_HEIGHT-3) /* promotion mandatory */
-                             cl.kind = promoChar == '=' ? IllegalMove : WhitePromotionKnight;
+                             cl.kind = promoChar == '=' ? IllegalMove : WhitePromotion;
                     else /* promotion optional, default is promote */
-                             cl.kind = promoChar == '=' ? WhiteNonPromotion : WhitePromotionQueen;
+                             cl.kind = promoChar == '=' ? WhiteNonPromotion : WhitePromotion;
                    
                 } else cl.kind = (promoChar == NULLCHAR || promoChar == 'x' || promoChar == '=') ?
                                             NormalMove : IllegalMove;
@@ -1141,25 +1052,22 @@ ChessMove LegalityTest(board, flags, rf, ff, rt, ft, promoChar)
                 if( (int) piece < (int) BlackWazir && (rf < BOARD_HEIGHT/3 || rt < BOARD_HEIGHT/3) ) {
                     if( (piece == BlackPawn || piece == BlackQueen) && rt < 1 ||
                          piece == BlackKnight && rt < 2 ) /* promotion obligatory */
-                             cl.kind = promoChar == '=' ? IllegalMove : BlackPromotionKnight;
+                             cl.kind = promoChar == '=' ? IllegalMove : BlackPromotion;
                     else /* promotion optional, default is promote */
-                             cl.kind = promoChar == '=' ? BlackNonPromotion : BlackPromotionQueen;
+                             cl.kind = promoChar == '=' ? BlackNonPromotion : BlackPromotion;
 
-                } else cl.kind = (promoChar == NULLCHAR || promoChar == 'x' || promoChar == '=') ?
-                                            NormalMove : IllegalMove;
+                } else cl.kind = (promoChar == NULLCHAR || promoChar == '=') ? NormalMove : IllegalMove;
             }
         }
     } else
-    if (promoChar != NULLCHAR && promoChar != 'x') {
+    if (promoChar != NULLCHAR) {
        if(promoChar == '=') cl.kind = IllegalMove; else // [HGM] shogi: no deferred promotion outside Shogi
-       if (cl.kind == WhitePromotionQueen || cl.kind == BlackPromotionQueen) {
-           cl.kind = 
-             PromoCharToMoveType((flags & F_WHITE_ON_MOVE) != 0, promoChar);
+       if (cl.kind == WhitePromotion || cl.kind == BlackPromotion) {
+           if(CharToPiece(promoChar) == EmptySquare) cl.kind = ImpossibleMove; // non-existing piece
        } else {
            cl.kind = IllegalMove;
        }
     }
-    /* [HGM] For promotions, 'ToQueen' = optional, 'ToKnight' = mandatory */
     return cl.kind;
 }
 
@@ -1317,52 +1225,41 @@ void Disambiguate(board, flags, closure)
        }
     }
 
+    if (c == 'x') c = NULLCHAR; // get rid of any 'x' (which should never happen?)
     if(gameInfo.variant == VariantShogi) {
-        /* [HGM] Shogi promotions. '=' means defer */
+        /* [HGM] Shogi promotions. On input, '=' means defer, NULL promote. Afterwards, c is set to '+' for promotions, NULL other */
         if(closure->rfIn != DROP_RANK && closure->kind == NormalMove) {
             ChessSquare piece = closure->piece;
-            if(c != NULLCHAR && c != 'x' && c != '+' && c != '=' &&
+            if(c != NULLCHAR && c != '+' && c != '=' &&
                ToUpper(PieceToChar(PROMOTED piece)) != ToUpper(c) ) 
-                    closure->kind = IllegalMove;
+                    closure->kind = IllegalMove; // the only allowed cases are '+', '=' and the promoted partner.
             else if(flags & F_WHITE_ON_MOVE) {
                 if( (int) piece < (int) WhiteWazir &&
                      (closure->rf >= BOARD_HEIGHT-(BOARD_HEIGHT/3) || closure->rt >= BOARD_HEIGHT-(BOARD_HEIGHT/3)) ) {
                     if( (piece == WhitePawn || piece == WhiteQueen) && closure->rt > BOARD_HEIGHT-2 ||
                          piece == WhiteKnight && closure->rt > BOARD_HEIGHT-3) /* promotion mandatory */
-                             closure->kind = c == '=' ? IllegalMove : WhitePromotionKnight;
+                             closure->kind = c == '=' ? IllegalMove : WhitePromotion;
                     else /* promotion optional, default is promote */
-                             closure->kind = c == '=' ? NormalMove  : WhitePromotionQueen;
-                    if(c != '=') closure->promoCharIn = 'q';
-                } else closure->kind = (c == NULLCHAR || c == 'x' || c == '=') ?
-                                            NormalMove : IllegalMove;
+                             closure->kind = c == '=' ? WhiteNonPromotion  : WhitePromotion;
+                } else closure->kind = (c == NULLCHAR || c == '=') ? NormalMove : IllegalMove;
             } else {
                 if( (int) piece < (int) BlackWazir && (closure->rf < BOARD_HEIGHT/3 || closure->rt < BOARD_HEIGHT/3) ) {
                     if( (piece == BlackPawn || piece == BlackQueen) && closure->rt < 1 ||
                          piece == BlackKnight && closure->rt < 2 ) /* promotion obligatory */
-                             closure->kind = c == '=' ? IllegalMove : BlackPromotionKnight;
+                             closure->kind = c == '=' ? IllegalMove : BlackPromotion;
                     else /* promotion optional, default is promote */
-                             closure->kind = c == '=' ? NormalMove  : BlackPromotionQueen;
-                    if(c != '=') closure->promoCharIn = 'q';
-                } else closure->kind = (c == NULLCHAR || c == 'x' || c == '=') ?
-                                            NormalMove : IllegalMove;
+                             closure->kind = c == '=' ? BlackNonPromotion  : BlackPromotion;
+                } else closure->kind = (c == NULLCHAR || c == '=') ? NormalMove : IllegalMove;
             }
         }
+        c = (closure->kind == WhitePromotion || closure->kind == BlackPromotion) ? '+' : NULLCHAR;
     } else
-    if (closure->promoCharIn != NULLCHAR && closure->promoCharIn != 'x') {
-       if (closure->kind == WhitePromotionQueen
-           || closure->kind == BlackPromotionQueen) {
-           closure->kind = 
-             PromoCharToMoveType((flags & F_WHITE_ON_MOVE) != 0,
-                                 closure->promoCharIn);
-       } else {
-           closure->kind = IllegalMove;
-       }
-    }
-    /* [HGM] returns 'q' for optional promotion, 'n' for mandatory */
-    if(closure->promoCharIn != '=')
-        closure->promoChar = ToLower(closure->promoCharIn);
-    else closure->promoChar = '=';
-    if (closure->promoChar == 'x') closure->promoChar = NULLCHAR;
+    if (closure->kind == WhitePromotion || closure->kind == BlackPromotion) {
+        if(c == NULLCHAR) c = 'q'; // even in Shatranj, Courier, Makruk, as Apply move corrects this to Ferz (how messy!)
+    } else if (c != NULLCHAR) closure->kind = IllegalMove;
+
+    closure->promoChar = ToLower(c); // this can be NULLCHAR! Note we keep original promoChar even if illegal.
+    if(c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare) closure->kind = ImpossibleMove; // but we cannot handle non-existing piece types! 
     if (closure->count > 1) {
        closure->kind = AmbiguousMove;
     }
@@ -1373,9 +1270,6 @@ void Disambiguate(board, flags, closure)
        */
        closure->kind = IllegalMove;
     }
-    if(closure->kind == IllegalMove)
-    /* [HGM] might be a variant we don't understand, pass on promotion info */
-        closure->promoChar = ToLower(closure->promoCharIn);
     if (appData.debugMode) {
         fprintf(debugFP, "Disambiguate out: %d(%d,%d)-(%d,%d) = %d (%c)\n",
         closure->piece,closure->ff,closure->rf,closure->ft,closure->rt,closure->promoChar,
@@ -1598,8 +1492,8 @@ ChessMove CoordsToAlgebraic(board, flags, rf, ff, rt, ft, promoChar, out)
                      (rf >= BOARD_HEIGHT-(BOARD_HEIGHT/3) || rt >= BOARD_HEIGHT-(BOARD_HEIGHT/3)) ) {
                     if( (piece == WhitePawn || piece == WhiteQueen) && rt > BOARD_HEIGHT-2 ||
                          piece == WhiteKnight && rt > BOARD_HEIGHT-3) /* promotion mandatory */
-                             cl.kind = promoChar == '=' ? IllegalMove : WhitePromotionKnight;
-                    else cl.kind =  WhitePromotionQueen; /* promotion optional */
+                             cl.kind = promoChar == '=' ? IllegalMove : WhitePromotion;
+                    else cl.kind =  WhitePromotion; /* promotion optional */
                    
                 } else cl.kind = (promoChar == NULLCHAR || promoChar == 'x' || promoChar == '=') ?
                                             NormalMove : IllegalMove;
@@ -1607,12 +1501,12 @@ ChessMove CoordsToAlgebraic(board, flags, rf, ff, rt, ft, promoChar, out)
                 if( (int) cl.piece < (int) BlackWazir && (rf < BOARD_HEIGHT/3 || rt < BOARD_HEIGHT/3) ) {
                     if( (piece == BlackPawn || piece == BlackQueen) && rt < 1 ||
                          piece == BlackKnight && rt < 2 ) /* promotion obligatory */
-                             cl.kind = promoChar == '=' ? IllegalMove : BlackPromotionKnight;
-                    else cl.kind =  BlackPromotionQueen; /* promotion optional */
+                             cl.kind = promoChar == '=' ? IllegalMove : BlackPromotion;
+                    else cl.kind =  BlackPromotion; /* promotion optional */
                 } else cl.kind = (promoChar == NULLCHAR || promoChar == 'x' || promoChar == '=') ?
                                             NormalMove : IllegalMove;
             }
-            if(cl.kind == WhitePromotionQueen || cl.kind == BlackPromotionQueen) {
+            if(cl.kind == WhitePromotion || cl.kind == BlackPromotion) {
                 /* for optional promotions append '+' or '=' */
                 if(promoChar == '=') {
                     *outp++ = '=';
index ca1681b..804362a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1718,176 +1718,176 @@ goto find_rule; \
 char *yytext;
 #line 1 "parser.l"
 #line 8 "parser.l"
-/*\r
- * parser.l -- lex parser of algebraic chess moves for XBoard\r
- *\r
- * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
- * Massachusetts.\r
- *\r
- * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005,\r
- * 2006, 2007, 2008, 2009 Free Software Foundation, Inc.\r
- *\r
- * The following terms apply to Digital Equipment Corporation's copyright\r
- * interest in XBoard:\r
- * ------------------------------------------------------------------------\r
- * All Rights Reserved\r
- *\r
- * Permission to use, copy, modify, and distribute this software and its\r
- * documentation for any purpose and without fee is hereby granted,\r
- * provided that the above copyright notice appear in all copies and that\r
- * both that copyright notice and this permission notice appear in\r
- * supporting documentation, and that the name of Digital not be\r
- * used in advertising or publicity pertaining to distribution of the\r
- * software without specific, written prior permission.\r
- *\r
- * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\r
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL\r
- * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\r
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,\r
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- * ------------------------------------------------------------------------\r
- *\r
- * The following terms apply to the enhanced version of XBoard\r
- * distributed by the Free Software Foundation:\r
- * ------------------------------------------------------------------------\r
- *\r
- * GNU XBoard is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or (at\r
- * your option) any later version.\r
- *\r
- * GNU XBoard is distributed in the hope that it will be useful, but\r
- * WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see http://www.gnu.org/licenses/.  \r
- *\r
- *------------------------------------------------------------------------\r
- ** See the file ChangeLog for a revision history.  */\r
-\r
-/* This parser handles all forms of promotion.\r
- * The parser resolves ambiguous moves by searching and check-testing.\r
- * It also parses comments of the form [anything] or (anything).\r
- *\r
- * [HGM] Parser extensively modified for bigger boards, Shogi-like syntax,\r
- * and unknow pieces. All pieces are now mandatory upper case, but can be\r
- * any letter A-Z. Files must be lower case (as before), but can run upto 'l'.\r
- * Ranks can be 0-9. The parser returns 0 for off-board files and ranks.\r
- * For an unknown piece (as mover or promotion piece) it returns\r
- * IllegalMove, like it does when the piece doesn't match.\r
- * Promotions can now also be appended Shogi-style, a bare '=' or '+',\r
- * and this is then returned as promotion character. The piece indicator\r
- * can be prefixed by a '+' to indicate it is a promoted piece.\r
- */\r
-\r
-#include "config.h"\r
-\r
-#define NO_CONSTRAINT  -1\r
-#undef YYLMAX\r
-#define YYLMAX                 4096\r
-#define UNPUT_BUF_SIZE         YYLMAX\r
-\r
-#ifdef FLEX_SCANNER\r
-/* yytext is probably a char*, but could be a char[].  yy_text is set\r
-   in YY_DECL below, because if yytext is a char*, its value is not\r
-   constant. */\r
-char *yy_text;\r
-#else /*!FLEX_SCANNER*/\r
-/* yytext is definitely a char[], so yy_text can be set here, statically. */\r
-char *yy_text = (char *) yytext;\r
-#endif\r
-\r
-#ifdef FLEX_SCANNER\r
-/* This is flex */\r
-/* [AP] use prototypes in function declarations */\r
-#define YY_USE_PROTOS\r
-\r
-#ifdef YY_USE_PROTOS\r
-#define YY_PROTO(proto) proto\r
-#else\r
-#define YY_PROTO(proto) ()\r
-#endif\r
-/* end of [AP] fix */\r
-\r
-#undef YY_INPUT\r
-#define YY_INPUT(buf, result, max_size) my_yy_input(buf, &result, max_size)\r
-#undef YY_DECL\r
-#define YY_DECL                     \\r
-    int _yylex YY_PROTO((void));    \\r
-    int yylex YY_PROTO((void))      \\r
-    {                               \\r
-       int result = _yylex();      \\r
-       yy_text = (char *) yytext;  \\r
-       return(result);             \\r
-    }                               \\r
-    int _yylex YY_PROTO((void))\r
-#else\r
-/* This is lex */\r
-#undef input\r
-#undef output\r
-#undef unput\r
-#endif\r
-\r
-/* The includes must be here, below the #undef input */\r
-\r
-#include <ctype.h>\r
-\r
-#if STDC_HEADERS\r
-# include <stdlib.h>\r
-# include <string.h>\r
-#else /* not STDC_HEADERS */\r
-# if HAVE_STRING_H\r
-#  include <string.h>\r
-# else /* not HAVE_STRING_H */\r
-#  include <strings.h>\r
-# endif /* not HAVE_STRING_H */\r
-#endif /* not STDC_HEADERS */\r
-\r
-#if HAVE_UNISTD_H\r
-# include <unistd.h>\r
-#endif\r
-\r
-#if defined(_amigados)\r
-# include <errno.h>\r
-# if HAVE_FCNTL_H\r
-#  include <fcntl.h>    /*  isatty() prototype  */\r
-# endif /*  HAVE_FCNTL_H        */\r
-#endif  /*  defined(_amigados)  */\r
-\r
-#include "common.h"\r
-#include "backend.h"\r
-#include "frontend.h"\r
-#include "parser.h"\r
-#include "moves.h"\r
-\r
-extern int PosFlags P((int));\r
-\r
-extern Board   boards[MAX_MOVES];\r
-int            yyboardindex;\r
-int             yyskipmoves = FALSE;\r
-char           currentMoveString[YYLMAX];\r
-#ifndef FLEX_SCANNER\r
-char           unputBuffer[UNPUT_BUF_SIZE];\r
-int            unputCount = 0;\r
-#endif\r
-\r
-#ifdef FLEX_SCANNER\r
-void my_yy_input P((char *buf, int *result, int max_size));\r
-#else /*!FLEX_SCANNER*/\r
-static int input P((void));\r
-static void output P((int ch));\r
-static void unput P((int ch));\r
-int yylook P((void));\r
-int yyback P((int *, int));\r
-#endif\r
-#undef yywrap\r
-int yywrap P((void));\r
-extern void CopyBoard P((Board to, Board from));\r
-\r
+/*
+ * parser.l -- lex parser of algebraic chess moves for XBoard
+ *
+ * Copyright 1991 by Digital Equipment Corporation, Maynard,
+ * Massachusetts.
+ *
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005,
+ * 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ *
+ * The following terms apply to Digital Equipment Corporation's copyright
+ * interest in XBoard:
+ * ------------------------------------------------------------------------
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Digital not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * ------------------------------------------------------------------------
+ *
+ * The following terms apply to the enhanced version of XBoard
+ * distributed by the Free Software Foundation:
+ * ------------------------------------------------------------------------
+ *
+ * GNU XBoard is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU XBoard is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.  
+ *
+ *------------------------------------------------------------------------
+ ** See the file ChangeLog for a revision history.  */
+
+/* This parser handles all forms of promotion.
+ * The parser resolves ambiguous moves by searching and check-testing.
+ * It also parses comments of the form [anything] or (anything).
+ *
+ * [HGM] Parser extensively modified for bigger boards, Shogi-like syntax,
+ * and unknow pieces. All pieces are now mandatory upper case, but can be
+ * any letter A-Z. Files must be lower case (as before), but can run upto 'l'.
+ * Ranks can be 0-9. The parser returns 0 for off-board files and ranks.
+ * For an unknown piece (as mover or promotion piece) it returns
+ * IllegalMove, like it does when the piece doesn't match.
+ * Promotions can now also be appended Shogi-style, a bare '=' or '+',
+ * and this is then returned as promotion character. The piece indicator
+ * can be prefixed by a '+' to indicate it is a promoted piece.
+ */
+
+#include "config.h"
+
+#define NO_CONSTRAINT  -1
+#undef YYLMAX
+#define YYLMAX                 4096
+#define UNPUT_BUF_SIZE         YYLMAX
+
+#ifdef FLEX_SCANNER
+/* yytext is probably a char*, but could be a char[].  yy_text is set
+   in YY_DECL below, because if yytext is a char*, its value is not
+   constant. */
+char *yy_text;
+#else /*!FLEX_SCANNER*/
+/* yytext is definitely a char[], so yy_text can be set here, statically. */
+char *yy_text = (char *) yytext;
+#endif
+
+#ifdef FLEX_SCANNER
+/* This is flex */
+/* [AP] use prototypes in function declarations */
+#define YY_USE_PROTOS
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+/* end of [AP] fix */
+
+#undef YY_INPUT
+#define YY_INPUT(buf, result, max_size) my_yy_input(buf, &result, max_size)
+#undef YY_DECL
+#define YY_DECL                     \
+    int _yylex YY_PROTO((void));    \
+    int yylex YY_PROTO((void))      \
+    {                               \
+       int result = _yylex();      \
+       yy_text = (char *) yytext;  \
+       return(result);             \
+    }                               \
+    int _yylex YY_PROTO((void))
+#else
+/* This is lex */
+#undef input
+#undef output
+#undef unput
+#endif
+
+/* The includes must be here, below the #undef input */
+
+#include <ctype.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <string.h>
+#else /* not STDC_HEADERS */
+# if HAVE_STRING_H
+#  include <string.h>
+# else /* not HAVE_STRING_H */
+#  include <strings.h>
+# endif /* not HAVE_STRING_H */
+#endif /* not STDC_HEADERS */
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#if defined(_amigados)
+# include <errno.h>
+# if HAVE_FCNTL_H
+#  include <fcntl.h>    /*  isatty() prototype  */
+# endif /*  HAVE_FCNTL_H        */
+#endif  /*  defined(_amigados)  */
+
+#include "common.h"
+#include "backend.h"
+#include "frontend.h"
+#include "parser.h"
+#include "moves.h"
+
+extern int PosFlags P((int));
+
+extern Board   boards[MAX_MOVES];
+int            yyboardindex;
+int             yyskipmoves = FALSE;
+char           currentMoveString[YYLMAX];
+#ifndef FLEX_SCANNER
+char           unputBuffer[UNPUT_BUF_SIZE];
+int            unputCount = 0;
+#endif
+
+#ifdef FLEX_SCANNER
+void my_yy_input P((char *buf, int *result, int max_size));
+#else /*!FLEX_SCANNER*/
+static int input P((void));
+static void output P((int ch));
+static void unput P((int ch));
+int yylook P((void));
+int yyback P((int *, int));
+#endif
+#undef yywrap
+int yywrap P((void));
+extern void CopyBoard P((Board to, Board from));
+
 #line 1892 "parser.c"
 
 #define INITIAL 0
@@ -2046,7 +2046,7 @@ YY_DECL
     
 #line 179 "parser.l"
 
-\r
+
 #line 2051 "parser.c"
 
        if ( !(yy_init) )
@@ -2163,162 +2163,169 @@ do_action:    /* This label is used only to access EOF actions. */
 case 1:
 YY_RULE_SETUP
 #line 181 "parser.l"
-{\r
-    /*\r
-     * Fully-qualified algebraic move, possibly with promotion\r
-     */\r
-    int skip1 = 0, skip2 = 0, skip3 = 0, promoted = 0;\r
-    ChessSquare piece;\r
-    ChessMove result;\r
-    char c;\r
-    \r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    if (yytext[0] == '+') skip1 = skip3 = promoted = 1; /* [HGM] Shogi promoted */\r
-\r
-    /* remove the / */\r
-    if (yytext[1+skip1] == '/')  skip1++; \r
-    \r
-    /* remove the [xX:-] */\r
-    if ((yytext[3+skip1] == 'x') || (yytext[3+skip1] == 'X') ||\r
-        (yytext[3+skip1] == '-') || (yytext[3+skip1] == ':')) skip2 = 1;\r
-    \r
-    currentMoveString[0] = yytext[1+skip1];\r
-    currentMoveString[1] = yytext[2+skip1];\r
-    currentMoveString[2] = yytext[3+skip1+skip2];\r
-    currentMoveString[3] = yytext[4+skip1+skip2];\r
-    currentMoveString[4] = NULLCHAR;\r
-    \r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "Parser Qa1b2: yyleng=%d\n",\r
-        yyleng);\r
-    }\r
-\r
-    if (yyleng-skip1-skip2 > 5) { char c;\r
-        if (yytext[yyleng-1] == ')') {\r
-            c = currentMoveString[4] = ToLower(yytext[yyleng-2]);\r
-       } else {\r
-            c = currentMoveString[4] = ToLower(yytext[yyleng-1]);\r
-       }\r
-       currentMoveString[5] = NULLCHAR;\r
-        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)\r
-            return IllegalMove; /* [HGM] promotion to invalid piece */\r
-    }\r
-\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "parser: %s\n", currentMoveString);\r
-    }\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[1] - ONE <  0            ||\r
-       currentMoveString[0] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[3] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[3] - ONE <  0            ||\r
-       currentMoveString[2] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[0] - AAA <  BOARD_LEFT   ||\r
-       currentMoveString[2] - AAA <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    piece = boards[yyboardindex]\r
-      [currentMoveString[1] - ONE][currentMoveString[0] - AAA];\r
-    if(promoted) piece = (ChessSquare) (DEMOTED piece);\r
-    c = PieceToChar(piece);\r
-    if(c == '~') c = PieceToChar((ChessSquare) (DEMOTED piece));\r
-    if (ToLower(yytext[skip3]) != ToLower(c))\r
-      return (int) IllegalMove;\r
-\r
-    result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
-                          currentMoveString[1] - ONE,\r
-                          currentMoveString[0] - AAA,\r
-                          currentMoveString[3] - ONE,\r
-                          currentMoveString[2] - AAA,\r
-                         currentMoveString[4]);\r
-\r
-    if (currentMoveString[4] == NULLCHAR &&\r
-        (result == WhitePromotionKnight || result == BlackPromotionKnight ||\r
-         result == WhitePromotionQueen  || result == BlackPromotionQueen)) {\r
-        currentMoveString[4] = PieceToChar(BlackQueen);\r
-       currentMoveString[5] = NULLCHAR;\r
-    }\r
-\r
-    return (int) result;\r
-}\r
+{
+    /*
+     * Fully-qualified algebraic move, possibly with promotion
+     */
+    int skip1 = 0, skip2 = 0, skip3 = 0, promoted = 0;
+    ChessSquare piece;
+    ChessMove result;
+    char c;
+    
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    if (yytext[0] == '+') skip1 = skip3 = promoted = 1; /* [HGM] Shogi promoted */
+
+    /* remove the / */
+    if (yytext[1+skip1] == '/')  skip1++; 
+    
+    /* remove the [xX:-] */
+    if ((yytext[3+skip1] == 'x') || (yytext[3+skip1] == 'X') ||
+        (yytext[3+skip1] == '-') || (yytext[3+skip1] == ':')) skip2 = 1;
+    
+    currentMoveString[0] = yytext[1+skip1];
+    currentMoveString[1] = yytext[2+skip1];
+    currentMoveString[2] = yytext[3+skip1+skip2];
+    currentMoveString[3] = yytext[4+skip1+skip2];
+    currentMoveString[4] = NULLCHAR;
+    
+    if (appData.debugMode) {
+        fprintf(debugFP, "Parser Qa1b2: yyleng=%d\n",
+        yyleng);
+    }
+
+    if (yyleng-skip1-skip2 > 5) { char c;
+        if (yytext[yyleng-1] == ')') {
+            c = currentMoveString[4] = ToLower(yytext[yyleng-2]);
+       } else {
+            c = currentMoveString[4] = ToLower(yytext[yyleng-1]);
+       }
+       currentMoveString[5] = NULLCHAR;
+        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)
+            return IllegalMove; /* [HGM] promotion to invalid piece */
+    }
+
+    if (appData.debugMode) {
+        fprintf(debugFP, "parser: %s\n", currentMoveString);
+    }
+    /* [HGM] do not allow values beyond board size */
+    if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[1] - ONE <  0            ||
+       currentMoveString[0] - AAA >= BOARD_RGHT   ||
+       currentMoveString[3] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[3] - ONE <  0            ||
+       currentMoveString[2] - AAA >= BOARD_RGHT   ||
+       currentMoveString[0] - AAA <  BOARD_LEFT   ||
+       currentMoveString[2] - AAA <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    piece = boards[yyboardindex]
+      [currentMoveString[1] - ONE][currentMoveString[0] - AAA];
+    if(promoted) piece = (ChessSquare) (DEMOTED piece);
+    c = PieceToChar(piece);
+    if(c == '~') c = PieceToChar((ChessSquare) (DEMOTED piece));
+    if (ToLower(yytext[skip3]) != ToLower(c))
+      return (int) IllegalMove;
+
+    result = LegalityTest(boards[yyboardindex],
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                          currentMoveString[1] - ONE,
+                          currentMoveString[0] - AAA,
+                          currentMoveString[3] - ONE,
+                          currentMoveString[2] - AAA,
+                         currentMoveString[4]);
+
+    if (currentMoveString[4] == NULLCHAR &&
+        (result == WhitePromotion  || result == BlackPromotion)) {
+        if(gameInfo.variant == VariantCourier || gameInfo.variant == VariantShatranj)
+            currentMoveString[4] = PieceToChar(BlackFerz);
+        else if(gameInfo.variant == VariantGreat)
+            currentMoveString[4] = PieceToChar(BlackMan);
+        else if(gameInfo.variant == VariantShogi)
+            currentMoveString[4] = '+';
+        else
+            currentMoveString[4] = PieceToChar(BlackQueen);
+       currentMoveString[5] = NULLCHAR;
+    }
+
+    return (int) result;
+}
        YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 263 "parser.l"
-{\r
-    /*\r
-     * Simple algebraic move, possibly with promotion\r
-     * [HGM] Engine moves are received in this format, with lower-case promoChar!\r
-     */\r
-    int skip = 0;\r
-    ChessMove result;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    /* remove the [xX:-] */\r
-    if ((yytext[2] == 'x') || (yytext[2] == 'X') ||\r
-       (yytext[2] == '-') || (yytext[2] == ':')) skip = 1;\r
-\r
-    currentMoveString[0] = yytext[0];\r
-    currentMoveString[1] = yytext[1];\r
-    currentMoveString[2] = yytext[2+skip];\r
-    currentMoveString[3] = yytext[3+skip];\r
-    currentMoveString[4] = NULLCHAR;\r
-\r
-    if (yyleng-skip > 4) { char c;\r
-       if (yytext[yyleng-1] == ')') {\r
-            c = currentMoveString[4] = ToLower(yytext[yyleng-2]);\r
-       } else {\r
-            c = currentMoveString[4] = ToLower(yytext[yyleng-1]);\r
-       }\r
-       currentMoveString[5] = NULLCHAR;\r
-        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)\r
-            return IllegalMove;\r
-    }\r
-\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[1] - ONE <  0            ||\r
-       currentMoveString[0] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[3] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[3] - ONE <  0            ||\r
-       currentMoveString[2] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[0] - AAA <  BOARD_LEFT   ||\r
-       currentMoveString[2] - AAA <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
-                          currentMoveString[1] - ONE,\r
-                          currentMoveString[0] - AAA,\r
-                          currentMoveString[3] - ONE,\r
-                          currentMoveString[2] - AAA,\r
-                         currentMoveString[4]);\r
-\r
+#line 269 "parser.l"
+{
+    /*
+     * Simple algebraic move, possibly with promotion
+     * [HGM] Engine moves are received in this format, with lower-case promoChar!
+     */
+    int skip = 0;
+    ChessMove result;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    /* remove the [xX:-] */
+    if ((yytext[2] == 'x') || (yytext[2] == 'X') ||
+       (yytext[2] == '-') || (yytext[2] == ':')) skip = 1;
+
+    currentMoveString[0] = yytext[0];
+    currentMoveString[1] = yytext[1];
+    currentMoveString[2] = yytext[2+skip];
+    currentMoveString[3] = yytext[3+skip];
+    currentMoveString[4] = NULLCHAR;
+
+    if (yyleng-skip > 4) { char c;
+       if (yytext[yyleng-1] == ')') {
+            c = currentMoveString[4] = ToLower(yytext[yyleng-2]);
+       } else {
+            c = currentMoveString[4] = ToLower(yytext[yyleng-1]);
+       }
+       currentMoveString[5] = NULLCHAR;
+        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)
+            return IllegalMove;
+    }
+
+    /* [HGM] do not allow values beyond board size */
+    if(currentMoveString[1] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[1] - ONE <  0            ||
+       currentMoveString[0] - AAA >= BOARD_RGHT   ||
+       currentMoveString[3] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[3] - ONE <  0            ||
+       currentMoveString[2] - AAA >= BOARD_RGHT   ||
+       currentMoveString[0] - AAA <  BOARD_LEFT   ||
+       currentMoveString[2] - AAA <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    result = LegalityTest(boards[yyboardindex],
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                          currentMoveString[1] - ONE,
+                          currentMoveString[0] - AAA,
+                          currentMoveString[3] - ONE,
+                          currentMoveString[2] - AAA,
+                         currentMoveString[4]);
+
     if (currentMoveString[4] == NULLCHAR) {
-      if(result == WhitePromotionKnight || result == BlackPromotionKnight ||
-         result == WhitePromotionQueen  || result == BlackPromotionQueen) {
+      if(result == WhitePromotion  || result == BlackPromotion) {
         if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
             currentMoveString[4] = PieceToChar(BlackFerz);
         else if(gameInfo.variant == VariantGreat)
             currentMoveString[4] = PieceToChar(BlackMan);
+        else if(gameInfo.variant == VariantShogi)
+            currentMoveString[4] = '+'; // Queen might not be defined in mini variants!
         else
             currentMoveString[4] = PieceToChar(BlackQueen);
        currentMoveString[5] = NULLCHAR;
       }
     } else if(appData.testLegality && // strip off unnecessary and false promo characters
-       !(result == WhitePromotionQueen  || result == BlackPromotionQueen ||
-         result == WhiteNonPromotion    || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
+       !(result == WhitePromotion  || result == BlackPromotion ||
+         result == WhiteNonPromotion || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
 
     return (int) result;
 }
        YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 331 "parser.l"
+#line 338 "parser.l"
 {
     /*
      * Simple algebraic move, in capitals
@@ -2358,649 +2365,646 @@ YY_RULE_SETUP
                           currentMoveString[2] - AAA,
                          currentMoveString[4]);
 
-    if (currentMoveString[4] == NULLCHAR &&\r
-        (result == WhitePromotionKnight || result == BlackPromotionKnight ||\r
-         result == WhitePromotionQueen  || result == BlackPromotionQueen)) {\r
-        if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)\r
-            currentMoveString[4] = PieceToChar(BlackFerz);\r
-        else if(gameInfo.variant == VariantGreat)\r
-            currentMoveString[4] = PieceToChar(BlackMan);\r
-        else\r
-            currentMoveString[4] = PieceToChar(BlackQueen);\r
-       currentMoveString[5] = NULLCHAR;\r
-    } else if(appData.testLegality && // strip off unnecessary and false promo characters
-       !(result == WhitePromotionQueen  || result == BlackPromotionQueen ||
-         result == WhiteNonPromotion    || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
-\r
-    return (int) result;\r
-}\r
+    if (currentMoveString[4] == NULLCHAR &&
+        (result == WhitePromotion  || result == BlackPromotion)) {
+        if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
+            currentMoveString[4] = PieceToChar(BlackFerz);
+        else if(gameInfo.variant == VariantGreat)
+            currentMoveString[4] = PieceToChar(BlackMan);
+        else
+            currentMoveString[4] = PieceToChar(BlackQueen);
+       currentMoveString[5] = NULLCHAR;
+    }
+
+    return (int) result;
+}
        YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 387 "parser.l"
-{\r
-    /*\r
-     * Pawn move, possibly with promotion\r
-     */\r
-    DisambiguateClosure cl;\r
-    int skip = 0; char c;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    /* remove the =() */\r
-    if (yytext[2] == '=' && yytext[3] != NULLCHAR) skip++;\r
-    if (yytext[2+skip] == '(') skip++;\r
-\r
-    cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;\r
-    cl.rfIn = -1;\r
-    cl.ffIn = yytext[0] - AAA;\r
-    cl.rtIn = yytext[1] - ONE;\r
-    cl.ftIn = yytext[0] - AAA;\r
-    c = cl.promoCharIn = ToLower(yytext[2+skip]);\r
-\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(cl.rtIn >= BOARD_HEIGHT ||\r
-       cl.rtIn <  0            ||\r
-       cl.ffIn >= BOARD_RGHT   ||\r
-       cl.ftIn <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare)\r
-      return IllegalMove;\r
-\r
-\r
-    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);\r
-\r
-    currentMoveString[0] = cl.ff + AAA;\r
-    currentMoveString[1] = cl.rf + ONE;\r
-    currentMoveString[2] = cl.ft + AAA;\r
-    currentMoveString[3] = cl.rt + ONE;\r
-    currentMoveString[4] = cl.promoChar;\r
-    currentMoveString[5] = NULLCHAR;\r
-\r
-    return (int) cl.kind;\r
-}\r
+#line 391 "parser.l"
+{
+    /*
+     * Pawn move, possibly with promotion
+     */
+    DisambiguateClosure cl;
+    int skip = 0; char c;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    /* remove the =() */
+    if (yytext[2] == '=' && yytext[3] != NULLCHAR) skip++;
+    if (yytext[2+skip] == '(') skip++;
+
+    cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;
+    cl.rfIn = -1;
+    cl.ffIn = yytext[0] - AAA;
+    cl.rtIn = yytext[1] - ONE;
+    cl.ftIn = yytext[0] - AAA;
+    c = cl.promoCharIn = ToLower(yytext[2+skip]);
+
+    /* [HGM] do not allow values beyond board size */
+    if(cl.rtIn >= BOARD_HEIGHT ||
+       cl.rtIn <  0            ||
+       cl.ffIn >= BOARD_RGHT   ||
+       cl.ftIn <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare)
+      return IllegalMove;
+
+
+    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);
+
+    currentMoveString[0] = cl.ff + AAA;
+    currentMoveString[1] = cl.rf + ONE;
+    currentMoveString[2] = cl.ft + AAA;
+    currentMoveString[3] = cl.rt + ONE;
+    currentMoveString[4] = cl.promoChar;
+    currentMoveString[5] = NULLCHAR;
+
+    return (int) cl.kind;
+}
        YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 431 "parser.l"
-{\r
-    /*\r
-     * Pawn capture, possibly with promotion, possibly ambiguous\r
-     */\r
-    DisambiguateClosure cl;\r
-    int skip1 = 0, skip2 = 0; char c;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    /* remove trailing ep or e.p. (nonstandard PGN) */\r
-    if (yytext[yyleng-1] == 'p') {\r
-      yyleng -= 2;\r
-      yytext[yyleng] = NULLCHAR;\r
-    } else if (yytext[yyleng-1] == '.') {\r
-      yyleng -= 4;\r
-      yytext[yyleng] = NULLCHAR;\r
-    }\r
-\r
-    /* remove the [xX:-] and =() */\r
-    if ((yytext[1] == 'x') || (yytext[1] == 'X')\r
-       || (yytext[1] == ':') || (yytext[1] == '-')) skip1 = 1;\r
-    if (yytext[2+skip1] == '=' && yytext[3+skip1] != NULLCHAR) skip2++;\r
-    if (yytext[2+skip1+skip2] == '(') skip2++;\r
-\r
-    cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;\r
-    cl.rfIn = -1;\r
-    cl.ffIn = yytext[0] - AAA;\r
-    cl.rtIn = -1;\r
-    cl.ftIn = yytext[1+skip1] - AAA;\r
-    c = cl.promoCharIn = yytext[2+skip1+skip2];\r
-\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(cl.ffIn >= BOARD_RGHT  ||\r
-       cl.ffIn <  BOARD_LEFT  ||\r
-       cl.ftIn >= BOARD_RGHT  ||\r
-       cl.ftIn <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare)\r
-      return IllegalMove;\r
-\r
-    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);\r
-\r
-    currentMoveString[0] = cl.ff + AAA;\r
-    currentMoveString[1] = cl.rf + ONE;\r
-    currentMoveString[2] = cl.ft + AAA;\r
-    currentMoveString[3] = cl.rt + ONE;\r
-    currentMoveString[4] = cl.promoChar;\r
-    currentMoveString[5] = NULLCHAR;\r
-\r
-    return (int) cl.kind;\r
-}\r
+#line 435 "parser.l"
+{
+    /*
+     * Pawn capture, possibly with promotion, possibly ambiguous
+     */
+    DisambiguateClosure cl;
+    int skip1 = 0, skip2 = 0; char c;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    /* remove trailing ep or e.p. (nonstandard PGN) */
+    if (yytext[yyleng-1] == 'p') {
+      yyleng -= 2;
+      yytext[yyleng] = NULLCHAR;
+    } else if (yytext[yyleng-1] == '.') {
+      yyleng -= 4;
+      yytext[yyleng] = NULLCHAR;
+    }
+
+    /* remove the [xX:-] and =() */
+    if ((yytext[1] == 'x') || (yytext[1] == 'X')
+       || (yytext[1] == ':') || (yytext[1] == '-')) skip1 = 1;
+    if (yytext[2+skip1] == '=' && yytext[3+skip1] != NULLCHAR) skip2++;
+    if (yytext[2+skip1+skip2] == '(') skip2++;
+
+    cl.pieceIn = WhiteOnMove(yyboardindex) ? WhitePawn : BlackPawn;
+    cl.rfIn = -1;
+    cl.ffIn = yytext[0] - AAA;
+    cl.rtIn = -1;
+    cl.ftIn = yytext[1+skip1] - AAA;
+    c = cl.promoCharIn = yytext[2+skip1+skip2];
+
+    /* [HGM] do not allow values beyond board size */
+    if(cl.ffIn >= BOARD_RGHT  ||
+       cl.ffIn <  BOARD_LEFT  ||
+       cl.ftIn >= BOARD_RGHT  ||
+       cl.ftIn <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare)
+      return IllegalMove;
+
+    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);
+
+    currentMoveString[0] = cl.ff + AAA;
+    currentMoveString[1] = cl.rf + ONE;
+    currentMoveString[2] = cl.ft + AAA;
+    currentMoveString[3] = cl.rt + ONE;
+    currentMoveString[4] = cl.promoChar;
+    currentMoveString[5] = NULLCHAR;
+
+    return (int) cl.kind;
+}
        YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 484 "parser.l"
-{\r
-    /*\r
-     * unambiguously abbreviated Pawn capture, possibly with promotion\r
-     */\r
-    int skip = 0;\r
-    ChessMove result; char c;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    /* remove trailing ep or e.p. (nonstandard PGN) */\r
-    if (yytext[yyleng-1] == 'p') {\r
-      yyleng -= 2;\r
-      yytext[yyleng] = NULLCHAR;\r
-    } else if (yytext[yyleng-1] == '.') {\r
-      yyleng -= 4;\r
-      yytext[yyleng] = NULLCHAR;\r
-    }\r
-\r
-    /* remove the [xX:-] */\r
-    if ((yytext[1] == 'x') || (yytext[1] == 'X')\r
-       || (yytext[1] == ':') || (yytext[1] == '-')) skip = 1;\r
-\r
-    currentMoveString[0] = yytext[0];\r
-    currentMoveString[2] = yytext[1+skip];\r
-    currentMoveString[3] = yytext[2+skip];\r
-\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(currentMoveString[0] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[3] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[3] - ONE <  0            ||\r
-       currentMoveString[2] - AAA >= BOARD_RGHT   ||\r
-       currentMoveString[0] - AAA <  BOARD_LEFT   ||\r
-       currentMoveString[2] - AAA <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */\r
-         currentMoveString[0] != currentMoveString[2] ) {\r
-        currentMoveString[1] = yytext[2+skip];\r
-    } else \r
-    if (WhiteOnMove(yyboardindex)) {\r
-        if (yytext[2+skip] == ONE) return (int) ImpossibleMove;\r
-       currentMoveString[1] = yytext[2+skip] - 1;\r
-       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != WhitePawn) \r
-               return ImpossibleMove;\r
-    } else {\r
-        currentMoveString[1] = currentMoveString[3] + 1;\r
-        if (currentMoveString[3] == ONE+BOARD_HEIGHT-1) return (int) ImpossibleMove;\r
-       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != BlackPawn) \r
-               return ImpossibleMove;\r
-    }\r
-    if (yyleng-skip > 3) {\r
-       if (yytext[yyleng-1] == ')')\r
-          c = currentMoveString[4] = ToLower(yytext[yyleng-2]);\r
-       else\r
-          c = currentMoveString[4] = ToLower(yytext[yyleng-1]);\r
-       currentMoveString[5] = NULLCHAR;\r
-        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)\r
-            return IllegalMove;\r
-    } else {\r
-       currentMoveString[4] = NULLCHAR;\r
-    }\r
-\r
-    result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
-                          currentMoveString[1] - ONE,\r
-                          currentMoveString[0] - AAA,\r
-                          currentMoveString[3] - ONE,\r
-                          currentMoveString[2] - AAA,\r
-                         currentMoveString[4]);\r
-\r
-    if (currentMoveString[4] == NULLCHAR &&\r
-        (result == WhitePromotionQueen  || result == BlackPromotionQueen ||\r
-         result == WhitePromotionKnight || result == BlackPromotionKnight)) {\r
-        currentMoveString[4] = PieceToChar(BlackQueen);\r
-       // [HGM] shatranj: take care of variants without Queen\r
-       if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)\r
-            currentMoveString[4] = PieceToChar(BlackFerz);\r
-       if(gameInfo.variant == VariantGreat)\r
-            currentMoveString[4] = PieceToChar(BlackMan);\r
-       currentMoveString[5] = NULLCHAR;\r
-    }\r
-\r
-    if (result != IllegalMove) return (int) result;\r
-\r
-    /* Special case: improperly written en passant capture */\r
-    if (WhiteOnMove(yyboardindex)) {\r
-       if (currentMoveString[3] == '5') {\r
-           currentMoveString[1] = '5';\r
-           currentMoveString[3] = '6';\r
-       } else {\r
-           return (int) IllegalMove;\r
-       }\r
-    } else {\r
-       if (currentMoveString[3] == '4') {\r
-           currentMoveString[1] = '4';\r
-           currentMoveString[3] = '3';\r
-       } else {\r
-           return (int) IllegalMove;\r
-       }\r
-    }\r
-\r
-    result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
-                          currentMoveString[1] - ONE,\r
-                          currentMoveString[0] - AAA,\r
-                          currentMoveString[3] - ONE,\r
-                          currentMoveString[2] - AAA,\r
-                         currentMoveString[4]);\r
-\r
-    if (result == WhiteCapturesEnPassant || result == BlackCapturesEnPassant)\r
-      return (int) result;\r
-    else\r
-      return (int) IllegalMove;\r
-}\r
+#line 488 "parser.l"
+{
+    /*
+     * unambiguously abbreviated Pawn capture, possibly with promotion
+     */
+    int skip = 0;
+    ChessMove result; char c;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    /* remove trailing ep or e.p. (nonstandard PGN) */
+    if (yytext[yyleng-1] == 'p') {
+      yyleng -= 2;
+      yytext[yyleng] = NULLCHAR;
+    } else if (yytext[yyleng-1] == '.') {
+      yyleng -= 4;
+      yytext[yyleng] = NULLCHAR;
+    }
+
+    /* remove the [xX:-] */
+    if ((yytext[1] == 'x') || (yytext[1] == 'X')
+       || (yytext[1] == ':') || (yytext[1] == '-')) skip = 1;
+
+    currentMoveString[0] = yytext[0];
+    currentMoveString[2] = yytext[1+skip];
+    currentMoveString[3] = yytext[2+skip];
+
+    /* [HGM] do not allow values beyond board size */
+    if(currentMoveString[0] - AAA >= BOARD_RGHT   ||
+       currentMoveString[3] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[3] - ONE <  0            ||
+       currentMoveString[2] - AAA >= BOARD_RGHT   ||
+       currentMoveString[0] - AAA <  BOARD_LEFT   ||
+       currentMoveString[2] - AAA <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */
+         currentMoveString[0] != currentMoveString[2] ) {
+        currentMoveString[1] = yytext[2+skip];
+    } else 
+    if (WhiteOnMove(yyboardindex)) {
+        if (yytext[2+skip] == ONE) return (int) ImpossibleMove;
+       currentMoveString[1] = yytext[2+skip] - 1;
+       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != WhitePawn) 
+               return ImpossibleMove;
+    } else {
+        currentMoveString[1] = currentMoveString[3] + 1;
+        if (currentMoveString[3] == ONE+BOARD_HEIGHT-1) return (int) ImpossibleMove;
+       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != BlackPawn) 
+               return ImpossibleMove;
+    }
+    if (yyleng-skip > 3) {
+       if (yytext[yyleng-1] == ')')
+          c = currentMoveString[4] = ToLower(yytext[yyleng-2]);
+       else
+          c = currentMoveString[4] = ToLower(yytext[yyleng-1]);
+       currentMoveString[5] = NULLCHAR;
+        if(c != '=' && c != '+' && CharToPiece(c) == EmptySquare)
+            return IllegalMove;
+    } else {
+       currentMoveString[4] = NULLCHAR;
+    }
+
+    result = LegalityTest(boards[yyboardindex],
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                          currentMoveString[1] - ONE,
+                          currentMoveString[0] - AAA,
+                          currentMoveString[3] - ONE,
+                          currentMoveString[2] - AAA,
+                         currentMoveString[4]);
+
+    if (currentMoveString[4] == NULLCHAR &&
+        (result == WhitePromotion  || result == BlackPromotion)) {
+        currentMoveString[4] = PieceToChar(BlackQueen);
+       // [HGM] shatranj: take care of variants without Queen
+       if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
+            currentMoveString[4] = PieceToChar(BlackFerz);
+       if(gameInfo.variant == VariantGreat)
+            currentMoveString[4] = PieceToChar(BlackMan);
+       currentMoveString[5] = NULLCHAR;
+    }
+
+    if (result != IllegalMove) return (int) result;
+
+    /* Special case: improperly written en passant capture */
+    if (WhiteOnMove(yyboardindex)) {
+       if (currentMoveString[3] == '5') {
+           currentMoveString[1] = '5';
+           currentMoveString[3] = '6';
+       } else {
+           return (int) IllegalMove;
+       }
+    } else {
+       if (currentMoveString[3] == '4') {
+           currentMoveString[1] = '4';
+           currentMoveString[3] = '3';
+       } else {
+           return (int) IllegalMove;
+       }
+    }
+
+    result = LegalityTest(boards[yyboardindex],
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                          currentMoveString[1] - ONE,
+                          currentMoveString[0] - AAA,
+                          currentMoveString[3] - ONE,
+                          currentMoveString[2] - AAA,
+                         currentMoveString[4]);
+
+    if (result == WhiteCapturesEnPassant || result == BlackCapturesEnPassant)
+      return (int) result;
+    else
+      return (int) IllegalMove;
+}
        YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 599 "parser.l"
-{\r
-    /*\r
-     * piece move, possibly ambiguous\r
-     */\r
-    DisambiguateClosure cl;\r
-    int skip = 0, skip2 = 0, promoted = 0;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    if(yytext[0] == '+') promoted = skip = skip2 = 1;\r
-\r
-    /* remove the [xX:-] */\r
-    if ((yytext[1+skip] == 'x') || (yytext[1+skip] == 'X')\r
-        || (yytext[1+skip] == ':') || (yytext[1+skip] == '-')) skip++;\r
-\r
-    if (WhiteOnMove(yyboardindex)) {\r
-        cl.pieceIn = CharToPiece(ToUpper(yytext[skip2]));\r
-    } else {\r
-        cl.pieceIn = CharToPiece(ToLower(yytext[skip2]));\r
-    }\r
-    if(promoted) cl.pieceIn = (ChessSquare) (PROMOTED cl.pieceIn);\r
-\r
-    cl.rfIn = -1;\r
-    cl.ffIn = -1;\r
-    cl.rtIn = yytext[2+skip] - ONE;\r
-    cl.ftIn = yytext[1+skip] - AAA;\r
-    cl.promoCharIn = NULLCHAR;\r
-\r
-    if(yyleng-skip > 3) /* [HGM] can have Shogi-style promotion */\r
-        cl.promoCharIn = yytext[yyleng-1];\r
-\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "Parser Qa1: yyleng=%d,  %d(%d,%d)-(%d,%d) = %d (%c)\n",\r
-        yyleng,\r
-        cl.pieceIn,cl.ffIn,cl.rfIn,cl.ftIn,cl.rtIn,cl.promoCharIn,cl.promoCharIn?cl.promoCharIn:' ');\r
-    }\r
-\r
-    /* [HGM] but do not allow values beyond board size */\r
-    if(cl.rtIn >= BOARD_HEIGHT ||\r
-       cl.rtIn <  0            ||\r
-       cl.ftIn >= BOARD_RGHT   ||\r
-       cl.ftIn <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);\r
-\r
-    currentMoveString[0] = cl.ff + AAA;\r
-    currentMoveString[1] = cl.rf + ONE;\r
-    currentMoveString[2] = cl.ft + AAA;\r
-    currentMoveString[3] = cl.rt + ONE;\r
-    currentMoveString[4] = cl.promoChar;\r
-    currentMoveString[5] = NULLCHAR;\r
-\r
-    return (int) cl.kind;\r
-}\r
+#line 602 "parser.l"
+{
+    /*
+     * piece move, possibly ambiguous
+     */
+    DisambiguateClosure cl;
+    int skip = 0, skip2 = 0, promoted = 0;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    if(yytext[0] == '+') promoted = skip = skip2 = 1;
+
+    /* remove the [xX:-] */
+    if ((yytext[1+skip] == 'x') || (yytext[1+skip] == 'X')
+        || (yytext[1+skip] == ':') || (yytext[1+skip] == '-')) skip++;
+
+    if (WhiteOnMove(yyboardindex)) {
+        cl.pieceIn = CharToPiece(ToUpper(yytext[skip2]));
+    } else {
+        cl.pieceIn = CharToPiece(ToLower(yytext[skip2]));
+    }
+    if(promoted) cl.pieceIn = (ChessSquare) (PROMOTED cl.pieceIn);
+
+    cl.rfIn = -1;
+    cl.ffIn = -1;
+    cl.rtIn = yytext[2+skip] - ONE;
+    cl.ftIn = yytext[1+skip] - AAA;
+    cl.promoCharIn = NULLCHAR;
+
+    if(yyleng-skip > 3) /* [HGM] can have Shogi-style promotion */
+        cl.promoCharIn = yytext[yyleng-1];
+
+    if (appData.debugMode) {
+        fprintf(debugFP, "Parser Qa1: yyleng=%d,  %d(%d,%d)-(%d,%d) = %d (%c)\n",
+        yyleng,
+        cl.pieceIn,cl.ffIn,cl.rfIn,cl.ftIn,cl.rtIn,cl.promoCharIn,cl.promoCharIn?cl.promoCharIn:' ');
+    }
+
+    /* [HGM] but do not allow values beyond board size */
+    if(cl.rtIn >= BOARD_HEIGHT ||
+       cl.rtIn <  0            ||
+       cl.ftIn >= BOARD_RGHT   ||
+       cl.ftIn <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);
+
+    currentMoveString[0] = cl.ff + AAA;
+    currentMoveString[1] = cl.rf + ONE;
+    currentMoveString[2] = cl.ft + AAA;
+    currentMoveString[3] = cl.rt + ONE;
+    currentMoveString[4] = cl.promoChar;
+    currentMoveString[5] = NULLCHAR;
+
+    return (int) cl.kind;
+}
        YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 655 "parser.l"
-{\r
-    /*\r
-     * piece move with rank or file disambiguator\r
-     */\r
-    DisambiguateClosure cl;\r
-    int skip = 0, skip2 = 0; int promoted=0;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    if(yytext[0]=='+') promoted = skip = skip2 = 1;\r
-\r
-    /* remove the [xX:-] */\r
-    if ((yytext[2+skip] == 'x') || (yytext[2+skip] == 'X')\r
-        || (yytext[2+skip] == ':') || (yytext[2+skip] == '-')) skip++;\r
-\r
-    if (WhiteOnMove(yyboardindex)) {\r
-        cl.pieceIn = CharToPiece(ToUpper(yytext[skip2]));\r
-    } else {\r
-        cl.pieceIn = CharToPiece(ToLower(yytext[skip2]));\r
-    }\r
-    if(promoted) cl.pieceIn = (ChessSquare) (PROMOTED cl.pieceIn);\r
-\r
-    if (isalpha(yytext[1+skip2])) {\r
-       cl.rfIn = -1;\r
-        cl.ffIn = yytext[1+skip2] - AAA;\r
-       \r
-        if(cl.ffIn >= BOARD_RGHT ||\r
-           cl.ffIn <  BOARD_LEFT   ) return 0;\r
-    } else {\r
-        cl.rfIn = yytext[1+skip2] - ONE;\r
-       cl.ffIn = -1;\r
-        if(cl.rfIn >= BOARD_HEIGHT ||\r
-           cl.rfIn <  0) return 0;\r
-    }\r
-    cl.rtIn = yytext[3+skip] - ONE;\r
-    cl.ftIn = yytext[2+skip] - AAA;\r
-    cl.promoCharIn = NULLCHAR;\r
-\r
-    if(yyleng-skip > 4) /* [HGM] can have Shogi-style promotion */\r
-        cl.promoCharIn = yytext[yyleng-1];\r
-\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(cl.rtIn >= BOARD_HEIGHT ||\r
-       cl.rtIn <  0            ||\r
-       cl.ftIn >= BOARD_RGHT   ||\r
-       cl.ftIn <  BOARD_LEFT     )\r
-      return ImpossibleMove;\r
-\r
-    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);\r
-\r
-    currentMoveString[0] = cl.ff + AAA;\r
-    currentMoveString[1] = cl.rf + ONE;\r
-    currentMoveString[2] = cl.ft + AAA;\r
-    currentMoveString[3] = cl.rt + ONE;\r
-    currentMoveString[4] = cl.promoChar;\r
-    currentMoveString[5] = NULLCHAR;\r
-\r
-    return (int) cl.kind;\r
-}\r
+#line 658 "parser.l"
+{
+    /*
+     * piece move with rank or file disambiguator
+     */
+    DisambiguateClosure cl;
+    int skip = 0, skip2 = 0; int promoted=0;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    if(yytext[0]=='+') promoted = skip = skip2 = 1;
+
+    /* remove the [xX:-] */
+    if ((yytext[2+skip] == 'x') || (yytext[2+skip] == 'X')
+        || (yytext[2+skip] == ':') || (yytext[2+skip] == '-')) skip++;
+
+    if (WhiteOnMove(yyboardindex)) {
+        cl.pieceIn = CharToPiece(ToUpper(yytext[skip2]));
+    } else {
+        cl.pieceIn = CharToPiece(ToLower(yytext[skip2]));
+    }
+    if(promoted) cl.pieceIn = (ChessSquare) (PROMOTED cl.pieceIn);
+
+    if (isalpha(yytext[1+skip2])) {
+       cl.rfIn = -1;
+        cl.ffIn = yytext[1+skip2] - AAA;
+       
+        if(cl.ffIn >= BOARD_RGHT ||
+           cl.ffIn <  BOARD_LEFT   ) return 0;
+    } else {
+        cl.rfIn = yytext[1+skip2] - ONE;
+       cl.ffIn = -1;
+        if(cl.rfIn >= BOARD_HEIGHT ||
+           cl.rfIn <  0) return 0;
+    }
+    cl.rtIn = yytext[3+skip] - ONE;
+    cl.ftIn = yytext[2+skip] - AAA;
+    cl.promoCharIn = NULLCHAR;
+
+    if(yyleng-skip > 4) /* [HGM] can have Shogi-style promotion */
+        cl.promoCharIn = yytext[yyleng-1];
+
+    /* [HGM] do not allow values beyond board size */
+    if(cl.rtIn >= BOARD_HEIGHT ||
+       cl.rtIn <  0            ||
+       cl.ftIn >= BOARD_RGHT   ||
+       cl.ftIn <  BOARD_LEFT     )
+      return ImpossibleMove;
+
+    Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl);
+
+    currentMoveString[0] = cl.ff + AAA;
+    currentMoveString[1] = cl.rf + ONE;
+    currentMoveString[2] = cl.ft + AAA;
+    currentMoveString[3] = cl.rt + ONE;
+    currentMoveString[4] = cl.promoChar;
+    currentMoveString[5] = NULLCHAR;
+
+    return (int) cl.kind;
+}
        YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 715 "parser.l"
-{\r
-    int rf, ff, rt, ft;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    /* [HGM] all squares referenced to board edges in stead of absolute */\r
-    if (WhiteOnMove(yyboardindex)) {\r
-        if (boards[yyboardindex][0][(BOARD_WIDTH-1)>>1] == WhiteKing) {\r
-           /* ICS wild castling */\r
-           rf = 0;\r
-            ff = (BOARD_WIDTH-1)>>1;\r
-           rt = 0;\r
-            ft = BOARD_RGHT-3;\r
-       } else {\r
-           rf = 0;\r
-            ff = BOARD_WIDTH>>1;\r
-           rt = 0;\r
-            ft = BOARD_LEFT+2;\r
-       }\r
-    } else{ \r
-        if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) {\r
-           /* ICS wild castling */\r
-            rf = BOARD_HEIGHT-1;\r
-            ff = (BOARD_WIDTH-1)>>1;\r
-            rt = BOARD_HEIGHT-1;\r
-            ft = BOARD_RGHT-3;\r
-       } else {\r
-            rf = BOARD_HEIGHT-1;\r
-            ff = BOARD_WIDTH>>1;\r
-            rt = BOARD_HEIGHT-1;\r
-            ft = BOARD_LEFT+2;\r
-       }\r
-    }\r
+#line 718 "parser.l"
+{
+    int rf, ff, rt, ft;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    /* [HGM] all squares referenced to board edges in stead of absolute */
+    if (WhiteOnMove(yyboardindex)) {
+        if (boards[yyboardindex][0][(BOARD_WIDTH-1)>>1] == WhiteKing) {
+           /* ICS wild castling */
+           rf = 0;
+            ff = (BOARD_WIDTH-1)>>1;
+           rt = 0;
+            ft = BOARD_RGHT-3;
+       } else {
+           rf = 0;
+            ff = BOARD_WIDTH>>1;
+           rt = 0;
+            ft = BOARD_LEFT+2;
+       }
+    } else{ 
+        if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) {
+           /* ICS wild castling */
+            rf = BOARD_HEIGHT-1;
+            ff = (BOARD_WIDTH-1)>>1;
+            rt = BOARD_HEIGHT-1;
+            ft = BOARD_RGHT-3;
+       } else {
+            rf = BOARD_HEIGHT-1;
+            ff = BOARD_WIDTH>>1;
+            rt = BOARD_HEIGHT-1;
+            ft = BOARD_LEFT+2;
+       }
+    }
     if(PosFlags(0) & F_FRC_TYPE_CASTLING) {
-        if (WhiteOnMove(yyboardindex)) {\r
-            ff = initialRights[2];\r
-            ft = initialRights[1];\r
-        } else {\r
-            ff = initialRights[5];\r
-            ft = initialRights[4];\r
-        }\r
-        if (appData.debugMode) \r
-        {\r
-          fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft);\r
-        };\r
-        if(ff < 0 || ft < 0) return 0;\r
-    }\r
-    sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE);\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "long castling %d %d\n", ff, ft);\r
-    }\r
-    return (int) LegalityTest(boards[yyboardindex],\r
-                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!\r
-                             rf, ff, rt, ft, NULLCHAR);\r
-}\r
+
+        if (WhiteOnMove(yyboardindex)) {
+            ff = initialRights[2];
+            ft = initialRights[1];
+        } else {
+            ff = initialRights[5];
+            ft = initialRights[4];
+        }
+        if (appData.debugMode) 
+        {
+          fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft);
+        };
+        if(ff < 0 || ft < 0) return 0;
+    }
+    sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE);
+    if (appData.debugMode) {
+        fprintf(debugFP, "long castling %d %d\n", ff, ft);
+    }
+    return (int) LegalityTest(boards[yyboardindex],
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!
+                             rf, ff, rt, ft, NULLCHAR);
+}
        YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 771 "parser.l"
-{\r
-    int rf, ff, rt, ft;\r
-\r
-    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */\r
-\r
-    if (WhiteOnMove(yyboardindex)) {\r
-        if (boards[yyboardindex][0][(BOARD_WIDTH-1)>>1] == WhiteKing) {\r
-           /* ICS wild castling */\r
-           rf = 0;\r
-            ff = (BOARD_WIDTH-1)>>1;\r
-           rt = 0;\r
-            ft = BOARD_LEFT+1;\r
-       } else {\r
-           rf = 0;\r
-            ff = BOARD_WIDTH>>1;\r
-           rt = 0;\r
-            ft = BOARD_RGHT-2;\r
-       }\r
-    } else {\r
-        if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) {\r
-           /* ICS wild castling */\r
-            rf = BOARD_HEIGHT-1;\r
-            ff = (BOARD_WIDTH-1)>>1;\r
-            rt = BOARD_HEIGHT-1;\r
-            ft = BOARD_LEFT+1;\r
-       } else {\r
-            rf = BOARD_HEIGHT-1;\r
-            ff = BOARD_WIDTH>>1;\r
-            rt = BOARD_HEIGHT-1;\r
-            ft = BOARD_RGHT-2;\r
-       }\r
-    }\r
+#line 775 "parser.l"
+{
+    int rf, ff, rt, ft;
+
+    if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */
+
+    if (WhiteOnMove(yyboardindex)) {
+        if (boards[yyboardindex][0][(BOARD_WIDTH-1)>>1] == WhiteKing) {
+           /* ICS wild castling */
+           rf = 0;
+            ff = (BOARD_WIDTH-1)>>1;
+           rt = 0;
+            ft = BOARD_LEFT+1;
+       } else {
+           rf = 0;
+            ff = BOARD_WIDTH>>1;
+           rt = 0;
+            ft = BOARD_RGHT-2;
+       }
+    } else {
+        if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) {
+           /* ICS wild castling */
+            rf = BOARD_HEIGHT-1;
+            ff = (BOARD_WIDTH-1)>>1;
+            rt = BOARD_HEIGHT-1;
+            ft = BOARD_LEFT+1;
+       } else {
+            rf = BOARD_HEIGHT-1;
+            ff = BOARD_WIDTH>>1;
+            rt = BOARD_HEIGHT-1;
+            ft = BOARD_RGHT-2;
+       }
+    }
     if(PosFlags(0) & F_FRC_TYPE_CASTLING) {
-        if (WhiteOnMove(yyboardindex)) {\r
-            ff = initialRights[2];\r
-            ft = initialRights[0];\r
-        } else {\r
-            ff = initialRights[5];\r
-            ft = initialRights[3];\r
-        }\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "Parser FRC short %d %d\n", ff, ft);\r
-    }\r
-        if(ff < 0 || ft < 0) return 0;\r
-    }\r
-    sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE);\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "short castling %d %d\n", ff, ft);\r
-    }\r
-\r
-    return (int) LegalityTest(boards[yyboardindex],\r
-                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!\r
-                             rf, ff, rt, ft, NULLCHAR);\r
-}\r
+        if (WhiteOnMove(yyboardindex)) {
+            ff = initialRights[2];
+            ft = initialRights[0];
+        } else {
+            ff = initialRights[5];
+            ft = initialRights[3];
+        }
+    if (appData.debugMode) {
+        fprintf(debugFP, "Parser FRC short %d %d\n", ff, ft);
+    }
+        if(ff < 0 || ft < 0) return 0;
+    }
+    sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE);
+    if (appData.debugMode) {
+        fprintf(debugFP, "short castling %d %d\n", ff, ft);
+    }
+
+    return (int) LegalityTest(boards[yyboardindex],
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!
+                             rf, ff, rt, ft, NULLCHAR);
+}
        YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 826 "parser.l"
-{\r
-    /* Bughouse piece drop. */\r
-    currentMoveString[1] = '@';\r
-    currentMoveString[2] = yytext[2];\r
-    currentMoveString[3] = yytext[3];\r
-    currentMoveString[4] = NULLCHAR;\r
-\r
-    if (appData.debugMode) {\r
-        fprintf(debugFP, "Drop: %s\n", currentMoveString);\r
-    }\r
-    /* [HGM] do not allow values beyond board size */\r
-    if(currentMoveString[3] - ONE >= BOARD_HEIGHT ||\r
-       currentMoveString[2] - AAA >= BOARD_WIDTH     )\r
-      return ImpossibleMove;\r
-\r
-    if (WhiteOnMove(yyboardindex)) {\r
-       currentMoveString[0] = ToUpper(yytext[0]);\r
-    } else {\r
-       currentMoveString[0] = ToLower(yytext[0]);\r
-    }\r
+#line 830 "parser.l"
+{
+    /* Bughouse piece drop. */
+    currentMoveString[1] = '@';
+    currentMoveString[2] = yytext[2];
+    currentMoveString[3] = yytext[3];
+    currentMoveString[4] = NULLCHAR;
+
+    if (appData.debugMode) {
+        fprintf(debugFP, "Drop: %s\n", currentMoveString);
+    }
+    /* [HGM] do not allow values beyond board size */
+    if(currentMoveString[3] - ONE >= BOARD_HEIGHT ||
+       currentMoveString[2] - AAA >= BOARD_WIDTH     )
+      return ImpossibleMove;
+
+    if (WhiteOnMove(yyboardindex)) {
+       currentMoveString[0] = ToUpper(yytext[0]);
+    } else {
+       currentMoveString[0] = ToLower(yytext[0]);
+    }
     return LegalityTest(boards[yyboardindex], PosFlags(yyboardindex), DROP_RANK, // [HGM] does drops now too
                         CharToPiece(currentMoveString[0]), currentMoveString[3] - ONE, currentMoveString[2] - AAA, NULLCHAR);
-}\r
+}
        YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 850 "parser.l"
-{\r
-    if (WhiteOnMove(yyboardindex))\r
-      return (int) BlackWins;\r
-    else\r
-      return (int) WhiteWins;\r
-}\r
+#line 854 "parser.l"
+{
+    if (WhiteOnMove(yyboardindex))
+      return (int) BlackWins;
+    else
+      return (int) WhiteWins;
+}
        YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 857 "parser.l"
-{\r
-    return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);\r
-}\r
+#line 861 "parser.l"
+{
+    return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);
+}
        YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 861 "parser.l"
-{\r
-    return (int) GameUnfinished;\r
-}\r
+#line 865 "parser.l"
+{
+    return (int) GameUnfinished;
+}
        YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 865 "parser.l"
-{\r
-    return (int) GameIsDrawn;\r
-}\r
+#line 869 "parser.l"
+{
+    return (int) GameIsDrawn;
+}
        YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 869 "parser.l"
-{\r
-    return (int) GameIsDrawn;\r
-}\r
+#line 873 "parser.l"
+{
+    return (int) GameIsDrawn;
+}
        YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 873 "parser.l"
-{\r
-    if (WhiteOnMove(yyboardindex))\r
-      return (int) BlackWins;\r
-    else\r
-      return (int) WhiteWins;\r
-}\r
+#line 877 "parser.l"
+{
+    if (WhiteOnMove(yyboardindex))
+      return (int) BlackWins;
+    else
+      return (int) WhiteWins;
+}
        YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 880 "parser.l"
-{\r
-    if (WhiteOnMove(yyboardindex))\r
-      return (int) BlackWins;\r
-    else\r
-      return (int) WhiteWins;\r
-}\r
+#line 884 "parser.l"
+{
+    if (WhiteOnMove(yyboardindex))
+      return (int) BlackWins;
+    else
+      return (int) WhiteWins;
+}
        YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 887 "parser.l"
-{\r
-    return (int) GameIsDrawn;\r
-}\r
+#line 891 "parser.l"
+{
+    return (int) GameIsDrawn;
+}
        YY_BREAK
 case 20:
 YY_RULE_SETUP
-#line 891 "parser.l"
-{\r
-    return (int) GameIsDrawn;\r
-}\r
+#line 895 "parser.l"
+{
+    return (int) GameIsDrawn;
+}
        YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 895 "parser.l"
-{ \r
-    return (int) (ToUpper(yytext[0]) == 'W' ? WhiteWins : BlackWins);\r
-}\r
+#line 899 "parser.l"
+{ 
+    return (int) (ToUpper(yytext[0]) == 'W' ? WhiteWins : BlackWins);
+}
        YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 899 "parser.l"
-{ \r
-    return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);\r
-}\r
+#line 903 "parser.l"
+{ 
+    return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins);
+}
        YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 903 "parser.l"
-{ \r
-    return (int) WhiteWins;\r
-}\r
+#line 907 "parser.l"
+{ 
+    return (int) WhiteWins;
+}
        YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 907 "parser.l"
-{ \r
-    return (int) BlackWins;\r
-}\r
+#line 911 "parser.l"
+{ 
+    return (int) BlackWins;
+}
        YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 911 "parser.l"
-{\r
-    return (int) GameIsDrawn;\r
-}\r
+#line 915 "parser.l"
+{
+    return (int) GameIsDrawn;
+}
        YY_BREAK
 case 26:
 YY_RULE_SETUP
-#line 915 "parser.l"
-{\r
-    return (int) GameUnfinished;\r
-}\r
+#line 919 "parser.l"
+{
+    return (int) GameUnfinished;
+}
        YY_BREAK
 case 27:
 /* rule 27 can match eol */
 YY_RULE_SETUP
-#line 919 "parser.l"
-{\r
-    /* move numbers */\r
-    if ((yyleng == 1) && (yytext[0] == '1'))\r
-      return (int) MoveNumberOne;\r
-}\r
+#line 923 "parser.l"
+{
+    /* move numbers */
+    if ((yyleng == 1) && (yytext[0] == '1'))
+      return (int) MoveNumberOne;
+}
        YY_BREAK
 case 28:
 YY_RULE_SETUP
-#line 925 "parser.l"
-{\r
-    /* elapsed time indication, e.g. (0:12) or {10:21.071} */ \r
-    return (int) ElapsedTime;\r
-}\r
+#line 929 "parser.l"
+{
+    /* elapsed time indication, e.g. (0:12) or {10:21.071} */ 
+    return (int) ElapsedTime;
+}
        YY_BREAK
 case 29:
 /* rule 29 can match eol */
 YY_RULE_SETUP
-#line 930 "parser.l"
-{\r
-    /* position diagram enclosed in [-- --] */\r
-    return (int) PositionDiagram;\r
-}\r
+#line 934 "parser.l"
+{
+    /* position diagram enclosed in [-- --] */
+    return (int) PositionDiagram;
+}
        YY_BREAK
 case 30:
 /* rule 30 can match eol */
@@ -3008,26 +3012,26 @@ case 30:
 (yy_c_buf_p) = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 935 "parser.l"
-{\r
-    /* position diagram enclosed in {-- --} */\r
-    return (int) PositionDiagram;\r
-}\r
+#line 939 "parser.l"
+{
+    /* position diagram enclosed in {-- --} */
+    return (int) PositionDiagram;
+}
        YY_BREAK
 case 31:
 /* rule 31 can match eol */
 YY_RULE_SETUP
-#line 940 "parser.l"
-{\r
-    return (int) PGNTag;\r
-}    \r
+#line 944 "parser.l"
+{
+    return (int) PGNTag;
+}    
        YY_BREAK
 case 32:
 YY_RULE_SETUP
-#line 944 "parser.l"
-{\r
-    return (int) GNUChessGame;\r
-}\r
+#line 948 "parser.l"
+{
+    return (int) GNUChessGame;
+}
        YY_BREAK
 case 33:
 /* rule 33 can match eol */
@@ -3035,89 +3039,89 @@ case 33:
 (yy_c_buf_p) = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 948 "parser.l"
-{\r
-    return (int) XBoardGame;\r
-}\r
+#line 952 "parser.l"
+{
+    return (int) XBoardGame;
+}
        YY_BREAK
 case 34:
 YY_RULE_SETUP
-#line 952 "parser.l"
-{                              /* numeric annotation glyph */\r
-    return (int) NAG;\r
-}\r
+#line 956 "parser.l"
+{                              /* numeric annotation glyph */
+    return (int) NAG;
+}
        YY_BREAK
 case 35:
 /* rule 35 can match eol */
 YY_RULE_SETUP
-#line 956 "parser.l"
-{                              /* anything in {} */\r
-    return (int) Comment; \r
-}\r
+#line 960 "parser.l"
+{                              /* anything in {} */
+    return (int) Comment; 
+}
        YY_BREAK
 case 36:
 *yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
 (yy_c_buf_p) = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 960 "parser.l"
-{                                          /* ; to end of line */\r
-    return (int) Comment;\r
-}\r
+#line 964 "parser.l"
+{                                          /* ; to end of line */
+    return (int) Comment;
+}
        YY_BREAK
 case 37:
 /* rule 37 can match eol */
 YY_RULE_SETUP
-#line 964 "parser.l"
-{                              /* anything in [] */\r
-    return (int) Comment; \r
-}\r
+#line 968 "parser.l"
+{                              /* anything in [] */
+    return (int) Comment; 
+}
        YY_BREAK
 case 38:
 /* rule 38 can match eol */
 YY_RULE_SETUP
-#line 968 "parser.l"
-{ /* very nested () */\r
-    return (int) Comment; \r
-}\r
+#line 972 "parser.l"
+{ /* very nested () */
+    return (int) Comment; 
+}
        YY_BREAK
 case 39:
 /* rule 39 can match eol */
 YY_RULE_SETUP
-#line 972 "parser.l"
-{                              /* >=2 chars in () */\r
-    return (int) Comment; \r
-}       \r
+#line 976 "parser.l"
+{                              /* >=2 chars in () */
+    return (int) Comment; 
+}       
        YY_BREAK
 case 40:
 /* rule 40 can match eol */
 YY_RULE_SETUP
-#line 976 "parser.l"
-{\r
-        /* Skip mail headers */\r
-}\r
+#line 980 "parser.l"
+{
+        /* Skip mail headers */
+}
        YY_BREAK
 case 41:
 YY_RULE_SETUP
-#line 980 "parser.l"
-{\r
-        /* Skip random words */\r
-}\r
+#line 984 "parser.l"
+{
+        /* Skip random words */
+}
        YY_BREAK
 case 42:
 /* rule 42 can match eol */
 YY_RULE_SETUP
-#line 984 "parser.l"
-{\r
-        /* Skip everything else */\r
-}\r
+#line 988 "parser.l"
+{
+        /* Skip everything else */
+}
        YY_BREAK
 case 43:
 YY_RULE_SETUP
-#line 988 "parser.l"
+#line 992 "parser.l"
 ECHO;
        YY_BREAK
-#line 3121 "parser.c"
+#line 3125 "parser.c"
                        case YY_STATE_EOF(INITIAL):
                                yyterminate();
 
@@ -4092,197 +4096,197 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 988 "parser.l"
+#line 992 "parser.l"
+
 
 
-\r
-\r
-static char *StringToLex;\r
-\r
-#ifndef FLEX_SCANNER\r
-static FILE *lexFP;\r
-\r
-static int input()\r
-{\r
-    int ret;\r
-    \r
-    if (StringToLex != NULL) {\r
-       ret = *StringToLex;\r
-       if (ret == NULLCHAR)\r
-         ret = EOF;\r
-       else\r
-         StringToLex++;\r
-    } else if (unputCount > 0) {\r
-       ret = unputBuffer[--unputCount];\r
-    } else {\r
-       ret = fgetc(lexFP);\r
-    }    \r
-\r
-    if (ret == EOF) \r
-      return 0;\r
-    else\r
-      return ret;\r
-}\r
-\r
-/*\r
- * Return offset of next pattern within current file\r
- */\r
-int yyoffset()\r
-{\r
-    int offset = ftell(lexFP) - unputCount;\r
-\r
-    if (offset < 0) {\r
-       offset = 0;\r
-    }\r
-    return(offset);\r
-}\r
\r
-static void output(ch)\r
-     int ch;\r
-{\r
-    if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unmatched character '%c' (0%o)\n",\r
-           ch, ch);\r
-}\r
-\r
-static void unput(ch)\r
-     int ch;\r
-{\r
-    if (ch == 0) return;\r
-    if (StringToLex != NULL) {\r
-       StringToLex--;\r
-    } else {\r
-       if (unputCount >= UNPUT_BUF_SIZE)\r
-         if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unput buffer overflow '%c' (0%o)\n",\r
-                 ch, ch);\r
-       unputBuffer[unputCount++] = ch;\r
-    }\r
-}\r
-\r
-/* Get ready to lex from a new file.  Kludge below sticks\r
-   an artificial newline at the front of the file, which the\r
-   above grammar ignores, but which makes ^ at start of pattern\r
-   match at the real start of the file.\r
-*/\r
-void yynewfile(f)\r
-     FILE *f;\r
-{\r
-    lexFP = f;\r
-    StringToLex = NULL;\r
-    unputCount = 0;\r
-    unput('\n'); /* kludge */\r
-}\r
-\r
-/* Get ready to lex from a string.  ^ at start of pattern WON'T\r
-   match at the start of the string!\r
-*/\r
-void yynewstr(s)\r
-     char *s;\r
-{\r
-    lexFP = NULL;\r
-    StringToLex = s;\r
-    unputCount = 0;\r
-}\r
-#endif /*!FLEX_SCANNER*/\r
-\r
-#ifdef FLEX_SCANNER\r
-void my_yy_input(buf, result, max_size)\r
-     char *buf;\r
-     int *result;\r
-     int max_size;\r
-{\r
-    int count;\r
-\r
-    if (StringToLex != NULL) {\r
-       count = 0;\r
-       while (*StringToLex != NULLCHAR) {\r
-           *buf++ = *StringToLex++;\r
-           count++;\r
-       }\r
-       *result = count;\r
-       return;\r
-    } else {\r
-       count = fread(buf, 1, max_size, yyin);\r
-       if (count == 0) {\r
-           *result = YY_NULL;\r
-       } else {\r
-           *result = count;\r
-       }\r
-       return;\r
-    }    \r
-}\r
-\r
-static YY_BUFFER_STATE my_file_buffer = NULL;\r
-\r
-/*\r
-    Return offset of next pattern in the current file.\r
-*/\r
-int yyoffset()\r
-{\r
-    int pos = yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf;\r
-\r
-    return(ftell(YY_CURRENT_BUFFER->yy_input_file) -\r
-         yy_n_chars + pos);\r
-}\r
-\r
-\r
-void yynewstr(s)\r
-     char *s;\r
-{\r
-    if (my_file_buffer != NULL)\r
-      yy_delete_buffer(my_file_buffer);\r
-    StringToLex = s;\r
-    my_file_buffer = yy_create_buffer(stdin,YY_BUF_SIZE);\r
-    yy_switch_to_buffer(my_file_buffer);\r
-}\r
-\r
-void yynewfile(f)\r
-     FILE *f;\r
-{\r
-    if (my_file_buffer != NULL)\r
-      yy_delete_buffer(my_file_buffer);\r
-    StringToLex = NULL;\r
-    my_file_buffer = yy_create_buffer(f,YY_BUF_SIZE);\r
-    yy_switch_to_buffer(my_file_buffer);\r
-}\r
-#endif /*FLEX_SCANNER*/\r
-\r
-int yywrap()\r
-{\r
-    return TRUE;\r
-}\r
-\r
-/* Parse a move from the given string s */\r
-/* ^ at start of pattern WON'T work here unless using flex */\r
-ChessMove yylexstr(boardIndex, s, text, len)\r
-     int boardIndex, len;\r
-     char *s, *text;\r
+
+static char *StringToLex;
+
+#ifndef FLEX_SCANNER
+static FILE *lexFP;
+
+static int input()
+{
+    int ret;
+    
+    if (StringToLex != NULL) {
+       ret = *StringToLex;
+       if (ret == NULLCHAR)
+         ret = EOF;
+       else
+         StringToLex++;
+    } else if (unputCount > 0) {
+       ret = unputBuffer[--unputCount];
+    } else {
+       ret = fgetc(lexFP);
+    }    
+
+    if (ret == EOF) 
+      return 0;
+    else
+      return ret;
+}
+
+/*
+ * Return offset of next pattern within current file
+ */
+int yyoffset()
+{
+    int offset = ftell(lexFP) - unputCount;
+
+    if (offset < 0) {
+       offset = 0;
+    }
+    return(offset);
+}
+static void output(ch)
+     int ch;
 {
-    ChessMove ret;\r
-    char *oldStringToLex;\r
-#ifdef FLEX_SCANNER\r
-    YY_BUFFER_STATE buffer, oldBuffer;\r
-#endif\r
-    \r
-    yyboardindex = boardIndex;\r
-    oldStringToLex = StringToLex;\r
-    StringToLex = s;\r
-#ifdef FLEX_SCANNER\r
-    buffer = yy_create_buffer(stdin,YY_BUF_SIZE);\r
-    oldBuffer = YY_CURRENT_BUFFER;\r
-    yy_switch_to_buffer(buffer);\r
-#endif /*FLEX_SCANNER*/\r
-\r
+    if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unmatched character '%c' (0%o)\n",
+           ch, ch);
+}
+
+static void unput(ch)
+     int ch;
+{
+    if (ch == 0) return;
+    if (StringToLex != NULL) {
+       StringToLex--;
+    } else {
+       if (unputCount >= UNPUT_BUF_SIZE)
+         if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unput buffer overflow '%c' (0%o)\n",
+                 ch, ch);
+       unputBuffer[unputCount++] = ch;
+    }
+}
+
+/* Get ready to lex from a new file.  Kludge below sticks
+   an artificial newline at the front of the file, which the
+   above grammar ignores, but which makes ^ at start of pattern
+   match at the real start of the file.
+*/
+void yynewfile(f)
+     FILE *f;
+{
+    lexFP = f;
+    StringToLex = NULL;
+    unputCount = 0;
+    unput('\n'); /* kludge */
+}
+
+/* Get ready to lex from a string.  ^ at start of pattern WON'T
+   match at the start of the string!
+*/
+void yynewstr(s)
+     char *s;
+{
+    lexFP = NULL;
+    StringToLex = s;
+    unputCount = 0;
+}
+#endif /*!FLEX_SCANNER*/
+
+#ifdef FLEX_SCANNER
+void my_yy_input(buf, result, max_size)
+     char *buf;
+     int *result;
+     int max_size;
+{
+    int count;
+
+    if (StringToLex != NULL) {
+       count = 0;
+       while (*StringToLex != NULLCHAR) {
+           *buf++ = *StringToLex++;
+           count++;
+       }
+       *result = count;
+       return;
+    } else {
+       count = fread(buf, 1, max_size, yyin);
+       if (count == 0) {
+           *result = YY_NULL;
+       } else {
+           *result = count;
+       }
+       return;
+    }    
+}
+
+static YY_BUFFER_STATE my_file_buffer = NULL;
+
+/*
+    Return offset of next pattern in the current file.
+*/
+int yyoffset()
+{
+    int pos = yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf;
+
+    return(ftell(YY_CURRENT_BUFFER->yy_input_file) -
+         yy_n_chars + pos);
+}
+
+
+void yynewstr(s)
+     char *s;
+{
+    if (my_file_buffer != NULL)
+      yy_delete_buffer(my_file_buffer);
+    StringToLex = s;
+    my_file_buffer = yy_create_buffer(stdin,YY_BUF_SIZE);
+    yy_switch_to_buffer(my_file_buffer);
+}
+
+void yynewfile(f)
+     FILE *f;
+{
+    if (my_file_buffer != NULL)
+      yy_delete_buffer(my_file_buffer);
+    StringToLex = NULL;
+    my_file_buffer = yy_create_buffer(f,YY_BUF_SIZE);
+    yy_switch_to_buffer(my_file_buffer);
+}
+#endif /*FLEX_SCANNER*/
+
+int yywrap()
+{
+    return TRUE;
+}
+
+/* Parse a move from the given string s */
+/* ^ at start of pattern WON'T work here unless using flex */
+ChessMove yylexstr(boardIndex, s, text, len)
+     int boardIndex, len;
+     char *s, *text;
+{
+    ChessMove ret;
+    char *oldStringToLex;
+#ifdef FLEX_SCANNER
+    YY_BUFFER_STATE buffer, oldBuffer;
+#endif
+    
+    yyboardindex = boardIndex;
+    oldStringToLex = StringToLex;
+    StringToLex = s;
+#ifdef FLEX_SCANNER
+    buffer = yy_create_buffer(stdin,YY_BUF_SIZE);
+    oldBuffer = YY_CURRENT_BUFFER;
+    yy_switch_to_buffer(buffer);
+#endif /*FLEX_SCANNER*/
+
     ret = (ChessMove) yylex();
      strncpy(text, yy_text, len-1); // [HGM] vari: yy_text is not available to caller after buffer switch ?!?
-     text[len-1] = NULLCHAR;\r
-\r
-#ifdef FLEX_SCANNER\r
-    if (oldBuffer != NULL) \r
-      yy_switch_to_buffer(oldBuffer);\r
-    yy_delete_buffer(buffer);\r
-#endif /*FLEX_SCANNER*/\r
-    StringToLex = oldStringToLex;\r
-\r
-    return ret;\r
-}\r
+     text[len-1] = NULLCHAR;
+
+#ifdef FLEX_SCANNER
+    if (oldBuffer != NULL) 
+      yy_switch_to_buffer(oldBuffer);
+    yy_delete_buffer(buffer);
+#endif /*FLEX_SCANNER*/
+    StringToLex = oldStringToLex;
+
+    return ret;
+}
 
index accd570..0e4f898 100644 (file)
--- a/parser.l
+++ b/parser.l
@@ -251,9 +251,15 @@ extern void CopyBoard P((Board to, Board from));
                          currentMoveString[4]);
 
     if (currentMoveString[4] == NULLCHAR &&
-        (result == WhitePromotionKnight || result == BlackPromotionKnight ||
-         result == WhitePromotionQueen  || result == BlackPromotionQueen)) {
-        currentMoveString[4] = PieceToChar(BlackQueen);
+        (result == WhitePromotion  || result == BlackPromotion)) {
+        if(gameInfo.variant == VariantCourier || gameInfo.variant == VariantShatranj)
+            currentMoveString[4] = PieceToChar(BlackFerz);
+        else if(gameInfo.variant == VariantGreat)
+            currentMoveString[4] = PieceToChar(BlackMan);
+        else if(gameInfo.variant == VariantShogi)
+            currentMoveString[4] = '+';
+        else
+            currentMoveString[4] = PieceToChar(BlackQueen);
        currentMoveString[5] = NULLCHAR;
     }
 
@@ -311,19 +317,20 @@ extern void CopyBoard P((Board to, Board from));
                          currentMoveString[4]);
 
     if (currentMoveString[4] == NULLCHAR) {
-      if(result == WhitePromotionKnight || result == BlackPromotionKnight ||
-         result == WhitePromotionQueen  || result == BlackPromotionQueen) {
+      if(result == WhitePromotion  || result == BlackPromotion) {
         if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
             currentMoveString[4] = PieceToChar(BlackFerz);
         else if(gameInfo.variant == VariantGreat)
             currentMoveString[4] = PieceToChar(BlackMan);
+        else if(gameInfo.variant == VariantShogi)
+            currentMoveString[4] = '+'; // Queen might not be defined in mini variants!
         else
             currentMoveString[4] = PieceToChar(BlackQueen);
        currentMoveString[5] = NULLCHAR;
       }
     } else if(appData.testLegality && // strip off unnecessary and false promo characters
-       !(result == WhitePromotionQueen  || result == BlackPromotionQueen ||
-         result == WhiteNonPromotion    || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
+       !(result == WhitePromotion  || result == BlackPromotion ||
+         result == WhiteNonPromotion || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
 
     return (int) result;
 }
@@ -368,8 +375,7 @@ extern void CopyBoard P((Board to, Board from));
                          currentMoveString[4]);
 
     if (currentMoveString[4] == NULLCHAR &&
-        (result == WhitePromotionKnight || result == BlackPromotionKnight ||
-         result == WhitePromotionQueen  || result == BlackPromotionQueen)) {
+        (result == WhitePromotion  || result == BlackPromotion)) {
         if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
             currentMoveString[4] = PieceToChar(BlackFerz);
         else if(gameInfo.variant == VariantGreat)
@@ -377,9 +383,7 @@ extern void CopyBoard P((Board to, Board from));
         else
             currentMoveString[4] = PieceToChar(BlackQueen);
        currentMoveString[5] = NULLCHAR;
-    } else if(appData.testLegality && // strip off unnecessary and false promo characters
-       !(result == WhitePromotionQueen  || result == BlackPromotionQueen ||
-         result == WhiteNonPromotion    || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR;
+    }
 
     return (int) result;
 }
@@ -552,8 +556,7 @@ extern void CopyBoard P((Board to, Board from));
                          currentMoveString[4]);
 
     if (currentMoveString[4] == NULLCHAR &&
-        (result == WhitePromotionQueen  || result == BlackPromotionQueen ||
-         result == WhitePromotionKnight || result == BlackPromotionKnight)) {
+        (result == WhitePromotion  || result == BlackPromotion)) {
         currentMoveString[4] = PieceToChar(BlackQueen);
        // [HGM] shatranj: take care of variants without Queen
        if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk)
@@ -746,6 +749,7 @@ extern void CopyBoard P((Board to, Board from));
        }
     }
     if(PosFlags(0) & F_FRC_TYPE_CASTLING) {
+
         if (WhiteOnMove(yyboardindex)) {
             ff = initialRights[2];
             ft = initialRights[1];