Add option for move exclusion
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 12 Apr 2018 21:47:19 +0000 (23:47 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 12 Apr 2018 21:47:19 +0000 (23:47 +0200)
A string option 'Exclude move:' is added for the benefit of GUIs that do
not support the exclude feature. By prefixing with a '!' the move can be
included again. To prevent crashing on an invalid move syntax, the routine
ParseMove() had to be made more robust, returning 0 in such cases.

dropper.c

index 24a1e62..6d8ae23 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -1725,15 +1725,14 @@ int
 ParseMove(int stm, char *s)
 {
   char prom = 0, f, f2, piece;
-  int m, r, r2, i, from;
+  int m=0, r, r2, i, from;
   if(sscanf(s, "%c@%c%d", &piece, &f, &r) == 3) { // drop
     f -= 'a', r--;
     m = 22*r + f;
     for(i=0; pieces[i]; i++) if(pieces[i] == piece) break;
     m += handSlot[COLOR - stm + (i & 15)] << 8; // force type to unpromoted before taking from hand
     if(i > 15) m += 11;
-  } else {
-    sscanf(s, "%c%d%c%d%c", &f2, &r2, &f, &r, &prom);
+  } else if(sscanf(s, "%c%d%c%d%c", &f2, &r2, &f, &r, &prom) >= 4) {
     f -= 'a'; f2 -= 'a'; r--, r2--;
     m = 22*r + f + ((from = 22*r2 + f2) << 8);
     if(prom == '\n') prom = 0;
@@ -1904,11 +1903,13 @@ printf("# command: %s\n", inBuf);
       printf("feature option=\"Resign -check 0\"\n");           // example of an engine-defined option
       printf("feature option=\"Contempt -spin 0 -200 200\"\n"); // and another one
       printf("feature option=\"Multi-PV margin -spin 0 0 10000\"\n");
+      printf("feature option=\"Exclude move: -string \"\n");
       printf("feature done=1\n");
       return 1;
     }
     if(!strcmp(command, "option")) { // engine-defined options that must abort search
       if(sscanf(inBuf+7, "Multi-PV margin=%d", &margin)  == 1) return 1;
+      if(sscanf(inBuf+7, "Exclude move:=%s", command)) { int i = (*command == '!'); moveMap[ParseMove(stm, command+i)] = !i; return 1; }
       return 1;
     }
     if(!strcmp(command, "sd"))      { sscanf(inBuf+2, "%d", &maxDepth);    return 1; }