Fix sweep promotions
[xboard.git] / backend.c
index f449d26..5774c4d 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5289,8 +5289,8 @@ Sweep (int step)
        else if(promoSweep == WhiteKing && step > 0) promoSweep = BlackKing;
        if(!step) step = -1;
     } while(PieceToChar(promoSweep) == '.' || PieceToChar(promoSweep) == '~' || promoSweep == pawn ||
-           appData.testLegality && (promoSweep == king ||
-           IS_SHOGI(gameInfo.variant) && promoSweep != CHUPROMOTED last && last != CHUPROMOTED promoSweep && last != promoSweep));
+           appData.testLegality && promoSweep == king ||
+           IS_SHOGI(gameInfo.variant) && promoSweep != CHUPROMOTED last && last != CHUPROMOTED promoSweep && last != promoSweep);
     if(toX >= 0) {
        int victim = boards[currentMove][toY][toX];
        boards[currentMove][toY][toX] = promoSweep;
@@ -7169,13 +7169,17 @@ void
 HoverEvent (int xPix, int yPix, int x, int y)
 {
        static char baseMarker[BOARD_RANKS][BOARD_FILES], baseLegal[BOARD_RANKS][BOARD_FILES];
+       static int oldX = -1, oldY = -1, oldFromX = -1, oldFromY = -1;
        int r, f;
        if(dragging == 2) DragPieceMove(xPix, yPix); // [HGM] lion: drag without button for second leg
        if(!first.highlight) return;
-       if(hiX == -1 && hiY == -1 && x == fromX && y == fromY) // record markings 
+       if(fromX != oldFromX || fromY != oldFromY)  oldX = oldY = -1; // kludge to fake entry on from-click
+       if(x == oldX && y == oldY) return; // only do something if we enter new square
+       oldFromX = fromX; oldFromY = fromY;
+       if(oldX == -1 && oldY == -1 && x == fromX && y == fromY) // record markings after from-change
          for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT; f++)
            baseMarker[r][f] = marker[r][f], baseLegal[r][f] = legal[r][f];
-       else if(hiX != x || hiY != y) {
+       else if(oldX != x || oldY != y) {
          // [HGM] lift: entered new to-square; redraw arrow, and inform engine
          for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT; f++)
            marker[r][f] = baseMarker[r][f], legal[r][f] = baseLegal[r][f];
@@ -7184,7 +7188,8 @@ HoverEvent (int xPix, int yPix, int x, int y)
            snprintf(buf, MSG_SIZ, "hover %c%d\n", x + AAA, y + ONE - '0');
            SendToProgram(buf, &first);
          }
-         SetHighlights(fromX, fromY, x, y);
+         oldX = x; oldY = y;
+//       SetHighlights(fromX, fromY, x, y);
        }
 }
 
@@ -7412,7 +7417,7 @@ LeftClick (ClickType clickType, int xPix, int yPix)
 
     clearFlag = 0;
 
-    if(gameMode != EditPosition && !appData.testLegality && !legal[y][x] && (x != killX || y != killY)) {
+    if(gameMode != EditPosition && !appData.testLegality && !legal[y][x] && (x != killX || y != killY) && !sweepSelecting) {
        if(dragging) DragPieceEnd(xPix, yPix), dragging = 0;
        DisplayMessage(_("only marked squares are legal"),"");
        DrawPosition(TRUE, NULL);
@@ -7424,7 +7429,7 @@ LeftClick (ClickType clickType, int xPix, int yPix)
     if(!sweepSelecting) {
        toX = x;
        toY = y;
-    } else sweepSelecting = 0; // this must be the up-click corresponding to the down-click that started the sweep
+    }
 
     saveAnimate = appData.animate;
     if (clickType == Press) {
@@ -7461,6 +7466,13 @@ LeftClick (ClickType clickType, int xPix, int yPix)
        } else {
            ClearHighlights();
        }
+    } else if(sweepSelecting) { // this must be the up-click corresponding to the down-click that started the sweep
+       sweepSelecting = 0;
+       if (appData.animate || appData.highlightLastMove) {
+           SetHighlights(fromX, fromY, toX, toY);
+       } else {
+           ClearHighlights();
+       }
     } else {
 #if 0
 // [HGM] this must be done after the move is made, as with arrow it could lead to a board redraw with piece still on from square