Fix illegal drops
[xboard.git] / backend.c
index f969aba..9a9d0a4 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5494,6 +5494,7 @@ char yy_textstr[8000];
 Boolean
 ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fromY, int *toX, int *toY, char *promoChar)
 {
+    int badFrom;
     *moveType = yylexstr(moveNum, move, yy_textstr, sizeof yy_textstr);
 
     switch (*moveType) {
@@ -5525,7 +5526,9 @@ ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fro
         *toX = currentMoveString[2] - AAA;
         *toY = currentMoveString[3] - ONE;
        *promoChar = currentMoveString[4];
-        if (*fromX < BOARD_LEFT || *fromX >= BOARD_RGHT || *fromY < 0 || *fromY >= BOARD_HEIGHT ||
+       badFrom = (*fromX < BOARD_LEFT || *fromX >= BOARD_RGHT || *fromY < 0 || *fromY >= BOARD_HEIGHT);
+       if(currentMoveString[1] == '@') { badFrom = FALSE; *fromX = CharToPiece(currentMoveString[0]); *fromY = DROP_RANK; } // illegal drop
+        if (badFrom ||
             *toX < BOARD_LEFT || *toX >= BOARD_RGHT || *toY < 0 || *toY >= BOARD_HEIGHT) {
     if (appData.debugMode) {
         fprintf(debugFP, "Off-board move (%d,%d)-(%d,%d)%c, type = %d\n", *fromX, *fromY, *toX, *toY, *promoChar, *moveType);
@@ -7495,7 +7498,7 @@ LeftClick (ClickType clickType, int xPix, int yPix)
            return;
        }
     }
-
+printf("to click %d,%d\n",x,y);
     /* fromX != -1 */
     if (clickType == Press && gameMode != EditPosition) {
        ChessSquare fromP;
@@ -7558,6 +7561,12 @@ LeftClick (ClickType clickType, int xPix, int yPix)
        // ignore clicks on holdings
        if(x < BOARD_LEFT || x >= BOARD_RGHT) return;
     }
+printf("A type=%d\n",clickType);
+
+    if(x == fromX && y == fromY && gameMode == EditPosition && SubtractTimeMarks(&lastClickTime, &prevClickTime) < 200) {
+       gatingPiece = boards[currentMove][fromY][fromX]; // prepare to copy rather than move
+       return;
+    }
 
     if (clickType == Release && x == fromX && y == fromY && killX < 0) {
        DragPieceEnd(xPix, yPix); dragging = 0;
@@ -7591,7 +7600,7 @@ LeftClick (ClickType clickType, int xPix, int yPix)
     }
 
     clearFlag = 0;
-
+printf("B\n");
     if(gameMode != EditPosition && !appData.testLegality && !legal[y][x] &&
        fromX >= BOARD_LEFT && fromX < BOARD_RGHT && (x != killX || y != killY) && !sweepSelecting) {
        if(dragging) DragPieceEnd(xPix, yPix), dragging = 0;
@@ -7599,7 +7608,7 @@ LeftClick (ClickType clickType, int xPix, int yPix)
        DrawPosition(TRUE, NULL);
        return; // ignore to-click
     }
-
+printf("(%d,%d)-(%d,%d) %d %d\n",fromX,fromY,toX,toY,x,y);
     /* we now have a different from- and (possibly off-board) to-square */
     /* Completed move */
     if(!sweepSelecting) {