Add disambiguation of move with unique piece
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 3 Mar 2012 22:32:11 +0000 (23:32 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Sat, 3 Mar 2012 22:32:11 +0000 (23:32 +0100)
If no pseudo-legal move of type Xa1 can be found, and only a single
piece of type X is on the board, successfully disambiguate the move
using that piece.

moves.c

diff --git a/moves.c b/moves.c
index f8b7857..1c4fe51 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -1331,14 +1331,23 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure)
         GenLegal(board, flags|F_IGNORE_CHECK, DisambiguateCallback, (VOIDSTAR) closure, closure->pieceIn);
        if (closure->count == 0) {
            /* No, it's not even that */
+         if(!appData.testLegality && closure->pieceIn != EmptySquare) {
+           int f, r; // if there is only a single piece of the requested type on the board, use that
+           closure->rt = closure->rtIn, closure->ft = closure->ftIn;
+           for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT; f++)
+               if(board[r][f] == closure->pieceIn) closure->count++, closure->rf = r, closure->ff = f;
+           if(closure->count > 1) illegal = 0; // ambiguous
+         }
+         if(closure->count == 0) {
            if (appData.debugMode) { int i, j;
                for(i=BOARD_HEIGHT-1; i>=0; i--) {
                    for(j=0; j<BOARD_WIDTH; j++)
-                       fprintf(debugFP, "%3d", (int) board[i][j]);
+                       fprintf(debugFP, "%3d", (int) board[i][j]);
                    fprintf(debugFP, "\n");
                }
            }
            return;
+         }
        }
     }