Make multi-PV mode accessible from XBoard protocol
[bonanza.git] / proce.c
diff --git a/proce.c b/proce.c
index 0f9223c..0a6df1a 100644 (file)
--- a/proce.c
+++ b/proce.c
@@ -52,7 +52,7 @@ static int cmd_thread( char **lasts );
 #endif
 
 #if defined(MPV)
-static int cmd_mpv( char **lasts );
+static int cmd_mpv( tree_t * restrict ptree, char **lasts );
 #endif
 
 static int proce_cui( tree_t * restrict ptree );
@@ -127,8 +127,14 @@ proce_xboard(char *line, const char *command, tree_t * restrict ptree)
   sscanf(line + strlen(command) + 1, "%d", &value);
 Out("# command = '%s'\n", line);
   if(0) ;
-  IF("protover") { Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER
-                       "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n"); }
+  IF("protover") {
+#if defined(MPV)
+                   Out("feature option=\"MultiPV -spin 1 1 100\"\n");
+                   Out("feature option=\"centi-Pawn margin -spin 200 0 25000\"\n");
+#endif
+                   Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER
+                       "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n");
+                 }
   IF("new")      { forceMode = plyNr = 0; SetTimes(); return 0; }
   IF("easy")     { strcpy(line, "ponder off"); return 0; }
   IF("hard")     { strcpy(line, "ponder on");  return 0; }
@@ -147,7 +153,10 @@ Out("# command = '%s'\n", line);
   IF("exit")     { return 0; }
   IF("variant")  { /* ignore, since it must be Shogi */; }
   IF("setboard") { ; }
-  IF("option")   { ; }
+  IF("option")   {
+                   if(sscanf(line+7, "MultiPV=%d", &value) == 1) { sprintf(line, "mpv num %d", value); return 0; }
+                   if(sscanf(line+7, "centi-Pawn margin=%d", &value) == 1) { sprintf(line, "mpv width %d", value); return 0; }
+                 }
   IF("level")    { int min, sec; float fsec=0.;
                    if(sscanf(line+6, "%d %d:%d %f", &movesPerSession, &min, &sec, &fsec) != 4)
                       sscanf(line+6, "%d %d %f", &movesPerSession, &min, &fsec);
@@ -208,6 +217,9 @@ proce_cui( tree_t * restrict ptree )
   if ( ! strcmp( token, "exit" ) )      { return cmd_exit(); }           // [HGM] analyze
   if ( ! strcmp( token, "move" ) )      { return cmd_move( ptree, &last ); }
   if ( ! strcmp( token, "undo" ) )      { return cmd_undo( ptree ); }    // [HGM] undo
+#if defined(MPV)
+  if ( ! strcmp( token, "mpv" ) )       { return cmd_mpv( ptree, &last ); }
+#endif
   analyze_mode = 0; // [HGM] analyze: all other commands terminate analysis
   if ( is_move( token ) ) { return cmd_usrmove( ptree, token, &last ); }
   if ( ! strcmp( token, "s" ) )         { return cmd_move_now(); }
@@ -235,9 +247,6 @@ proce_cui( tree_t * restrict ptree )
 #if defined(DEKUNOBOU)
   if ( ! strcmp( token, "dekunobou" ) ) { return cmd_dek( &last ); }
 #endif
-#if defined(MPV)
-  if ( ! strcmp( token, "mpv" ) )       { return cmd_mpv( &last ); }
-#endif
 #if defined(TLP)
   if ( ! strcmp( token, "tlp" ) )       { return cmd_thread( &last ); }
 #endif
@@ -1537,7 +1546,7 @@ cmd_learn( tree_t * restrict ptree, char **lasts )
 
 #if defined(MPV)
 static int
-cmd_mpv( char **lasts )
+cmd_mpv( tree_t * restrict ptree, char **lasts )
 {
   const char *str = strtok_r( NULL, str_delimiters, lasts );
   char *ptr;
@@ -1567,6 +1576,8 @@ cmd_mpv( char **lasts )
 
       mpv_num = (int)l;
 
+      if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue changing num
+
       return 1;
     }
   else if ( ! strcmp( str, "width" ) )
@@ -1588,6 +1599,8 @@ cmd_mpv( char **lasts )
 
       mpv_width = (int)l;
 
+      if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue after changing width
+
       return 1;
     }