changes from H.G. Muller; version 4.3.12
[xboard.git] / moves.c
diff --git a/moves.c b/moves.c
index ddf3ee9..deb245f 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -281,9 +281,7 @@ void GenPseudoLegal(board, flags, epfile, callback, closure)
              if (!BlackPiece(board[rf][ff])) continue;\r
          }\r
           m = 0; piece = board[rf][ff];\r
-          if(gameInfo.variant == VariantCrazyhouse &&\r
-              ( (int) piece > (int) WhiteQueen && (int) piece < (int) WhiteKing\r
-             || (int) piece > (int) BlackQueen && (int) piece < (int) BlackKing ))\r
+          if(PieceToChar(piece) == '~') \r
                  piece = (ChessSquare) ( DEMOTED piece );\r
           if(gameInfo.variant == VariantShogi)\r
                  piece = (ChessSquare) ( SHOGI piece );\r
@@ -294,7 +292,7 @@ void GenPseudoLegal(board, flags, epfile, callback, closure)
              /* can't happen ([HGM] except for faries...) */\r
              break;\r
 \r
-           case WhitePawn:\r
+             case WhitePawn:\r
               if(gameInfo.variant == VariantXiangqi) {\r
                   /* [HGM] capture and move straight ahead in Xiangqi */\r
                   if (rf < BOARD_HEIGHT-1 &&\r
@@ -1099,7 +1097,10 @@ void DisambiguateCallback(board, flags, kind, rf, ff, rt, ft, closure)
 {\r
     register DisambiguateClosure *cl = (DisambiguateClosure *) closure;\r
 \r
-    if ((cl->pieceIn == EmptySquare || cl->pieceIn == board[rf][ff]) &&\r
+    if ((cl->pieceIn == EmptySquare || cl->pieceIn == board[rf][ff]\r
+         || PieceToChar(board[rf][ff]) == '~'\r
+              && cl->pieceIn == (ChessSquare)(DEMOTED board[rf][ff])\r
+                                                                      ) &&\r
        (cl->rfIn == -1 || cl->rfIn == rf) &&\r
        (cl->ffIn == -1 || cl->ffIn == ff) &&\r
        (cl->rtIn == -1 || cl->rtIn == rt) &&\r
@@ -1245,7 +1246,10 @@ void CoordsToAlgebraicCallback(board, flags, kind, rf, ff, rt, ft, closure)
       (CoordsToAlgebraicClosure *) closure;\r
 \r
     if (rt == cl->rt && ft == cl->ft &&\r
-       board[rf][ff] == cl->piece) {\r
+        (board[rf][ff] == cl->piece\r
+         || PieceToChar(board[rf][ff]) == '~' &&\r
+            (ChessSquare) (DEMOTED board[rf][ff]) == cl->piece)\r
+                                     ) {\r
        if (rf == cl->rf) {\r
            if (ff == cl->ff) {\r
                cl->kind = kind; /* this is the move we want */\r
@@ -1275,7 +1279,7 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
 {\r
     ChessSquare piece;\r
     ChessMove kind;\r
-    char *outp = out;\r
+    char *outp = out, c;\r
     CoordsToAlgebraicClosure cl;\r
     \r
     if (rf == DROP_RANK) {\r
@@ -1287,20 +1291,18 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
            *outp++ = rt + ONE;\r
         else { *outp++ = (rt+ONE-'0')/10 + '0';*outp++ = (rt+ONE-'0')%10 + '0'; }\r
        *outp = NULLCHAR;\r
-        AlphaRank(out, 5);\r
        return (flags & F_WHITE_ON_MOVE) ? WhiteDrop : BlackDrop;\r
     }\r
 \r
     if (promoChar == 'x') promoChar = NULLCHAR;\r
     piece = board[rf][ff];\r
+    if(PieceToChar(piece)=='~') piece = (ChessSquare)(DEMOTED piece);\r
 \r
   if (appData.debugMode)\r
           fprintf(debugFP, "CoordsToAlgebraic, piece=%d\n", (int)piece);\r
     switch (piece) {\r
       case WhitePawn:\r
       case BlackPawn:\r
-  if (appData.debugMode)\r
-          fprintf(debugFP, "CoordsToAlgebraic, Pawn\n");\r
         kind = LegalityTest(board, flags, epfile, initialRights, rf, ff, rt, ft, promoChar);\r
        if (kind == IllegalMove && !(flags&F_IGNORE_CHECK)) {\r
            /* Keep short notation if move is illegal only because it\r
@@ -1338,7 +1340,6 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
             }\r
             *outp = NULLCHAR;\r
        }\r
-        AlphaRank(out, 10);\r
         return kind;\r
 \r
        \r
@@ -1404,13 +1405,14 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
           else "N1f3" or "N5xf7",\r
           else "Ng1f3" or "Ng5xf7".\r
        */\r
-        if(PieceToChar(piece) == '.') {\r
+        c = PieceToChar(piece) ;\r
+        if( c == '~' || c == '+') {\r
            /* [HGM] print nonexistent piece as its demoted version */\r
            piece = (ChessSquare) (DEMOTED piece);\r
-           if( gameInfo.variant == VariantShogi )\r
-                *outp++ = '+';\r
         }\r
+        if(c=='+') *outp++ = c;\r
         *outp++ = ToUpper(PieceToChar(piece));\r
+\r
        if (cl.file || (cl.either && !cl.rank)) {\r
             *outp++ = ff + AAA;\r
        }\r
@@ -1465,7 +1467,6 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
                 }\r
             }\r
         }\r
-        AlphaRank(out, 10);\r
         return cl.kind;\r
        \r
       /* [HGM] Always long notation for fairies we don't know */\r
@@ -1506,7 +1507,6 @@ ChessMove CoordsToAlgebraic(board, flags, epfile,
     }\r
     *outp = NULLCHAR;\r
 \r
-    AlphaRank(out, 0);\r
     return IllegalMove;\r
 }\r
 \r