Let second click on piece make only capture, with -oneClickMove
[xboard.git] / backend.c
index a54c6cc..42f434e 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5338,6 +5338,8 @@ SendBoard(cps, moveNum)
     setboardSpoiledMachineBlack = 0; /* [HGM] assume WB 4.2.7 already solves this after sending setboard */
 }
 
+static int autoQueen; // [HGM] oneclick
+
 int
 HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice)
 {
@@ -5408,7 +5410,7 @@ HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice)
        *promoChoice = PieceToChar(BlackFerz);  // no choice
        return FALSE;
     }
-    if(appData.alwaysPromoteToQueen) { // predetermined
+    if(autoQueen) { // predetermined
        if(gameInfo.variant == VariantSuicide || gameInfo.variant == VariantLosers)
             *promoChoice = PieceToChar(BlackKing); // in Suicide Q is the last thing we want
        else *promoChoice = PieceToChar(BlackQueen);
@@ -5550,7 +5552,7 @@ OKToStartUserMove(x, y)
 }
 
 Boolean
-OnlyMove(int *x, int *y) {
+OnlyMove(int *x, int *y, Boolean captures) {
     DisambiguateClosure cl;
     if (appData.zippyPlay) return FALSE;
     switch(gameMode) {
@@ -5573,7 +5575,11 @@ OnlyMove(int *x, int *y) {
     cl.ftIn = -1;
     cl.promoCharIn = NULLCHAR;
     Disambiguate(boards[currentMove], PosFlags(currentMove), &cl);
-    if(cl.kind == NormalMove) {
+    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 == WhiteCapturesEnPassant || cl.kind == BlackCapturesEnPassant) {
       fromX = cl.ff;
       fromY = cl.rf;
       *x = cl.ft;
@@ -5588,11 +5594,16 @@ OnlyMove(int *x, int *y) {
     cl.ftIn = *x;
     cl.promoCharIn = NULLCHAR;
     Disambiguate(boards[currentMove], PosFlags(currentMove), &cl);
-    if(cl.kind == NormalMove) {
+    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 == WhiteCapturesEnPassant || cl.kind == BlackCapturesEnPassant) {
       fromX = cl.ff;
       fromY = cl.rf;
       *x = cl.ft;
       *y = cl.rt;
+      autoQueen = TRUE; // act as if autoQueen on when we click to-square
       return TRUE;
     }
     return FALSE;
@@ -6087,8 +6098,10 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
               || x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize) )
        return;
 
+    autoQueen = appData.alwaysPromoteToQueen;
+
     if (fromX == -1) {
-      if(!appData.oneClick || !OnlyMove(&x, &y)) {
+      if(!appData.oneClick || !OnlyMove(&x, &y, FALSE)) {
        if (clickType == Press) {
            /* First square */
            if (OKToStartUserMove(x, y)) {
@@ -6129,6 +6142,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
             !(fromP == BlackKing && toP == BlackRook && frc))) {
            /* Clicked again on same color piece -- changed his mind */
            second = (x == fromX && y == fromY);
+          if(!second || !OnlyMove(&x, &y, TRUE)) {
            if (appData.highlightDragging) {
                SetHighlights(x, y, -1, -1);
            } else {
@@ -6141,6 +6155,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
                DragPieceBegin(xPix, yPix);
            }
            return;
+          }
        }
        // ignore clicks on holdings
        if(x < BOARD_LEFT || x >= BOARD_RGHT) return;
@@ -8706,6 +8721,8 @@ GameEnds(result, resultDetails, whosays)
              result, resultDetails ? resultDetails : "(null)", whosays);
     }
 
+    fromX = fromY = -1; // [HGM] abort any move the user is entering.
+
     if (appData.icsActive && (whosays == GE_ENGINE || whosays >= GE_ENGINE1)) {
        /* If we are playing on ICS, the server decides when the
           game is over, but the engine can offer to draw, claim