version 1.4w10UCIb16
[polyglot.git] / adapter.cpp
index d51cc25..e27c114 100644 (file)
@@ -116,6 +116,7 @@ static void stop_search    ();
 static void send_board     (int extra_move);\r
 static void send_pv        ();\r
 \r
+static void send_xboard_options ();\r
 \r
 static void learn          (int result);\r
 \r
@@ -267,12 +268,6 @@ static void xboard_step(char string[]) {
                     option_set("UCI","true");\r
                     return;\r
             }else{\r
-                if(!book_is_open() && option_get_bool("Book")){\r
-                    // restore old behaviour in xboard mode\r
-                    // missing book is fatal\r
-                     my_fatal("xboard_step(): can't open file \"%s\": %s\n",\r
-                             option_get_string("BookFile"),strerror(errno));\r
-                }\r
                  //uci_send_isready(Uci); // In UCI mode this done by the GUI\r
                  //Grrr...Toga can fixes the number of threads after "isready"\r
                  //So we delay "isready" \r
@@ -478,49 +473,7 @@ static void xboard_step(char string[]) {
 \r
                } else if (match(string,"protover *")) {\r
 \r
-                       XB->proto_ver = atoi(Star[0]);\r
-                       ASSERT(XB->proto_ver>=2);\r
-\r
-                       gui_send(GUI,"feature done=0");\r
-\r
-                       gui_send(GUI,"feature analyze=1");\r
-                       gui_send(GUI,"feature colors=0");\r
-                       gui_send(GUI,"feature draw=1");\r
-                       gui_send(GUI,"feature ics=1");\r
-                       gui_send(GUI,"feature myname=\"%s\"",option_get_string("EngineName"));\r
-                       gui_send(GUI,"feature name=1");\r
-                       gui_send(GUI,"feature pause=0");\r
-                       gui_send(GUI,"feature ping=1");\r
-                       gui_send(GUI,"feature playother=1");\r
-                       gui_send(GUI,"feature reuse=1");\r
-                       gui_send(GUI,"feature san=0");\r
-                       gui_send(GUI,"feature setboard=1");\r
-                       gui_send(GUI,"feature sigint=0");\r
-                       gui_send(GUI,"feature sigterm=0");\r
-                       gui_send(GUI,"feature time=1");\r
-                       gui_send(GUI,"feature usermove=1");\r
-            if (XB->has_feature_memory){\r
-                gui_send(GUI,"feature memory=1");\r
-            }\r
-            if (XB->has_feature_smp){\r
-                gui_send(GUI,"feature smp=1");\r
-            }\r
-            if (XB->has_feature_egt){\r
-                // TODO: support for other types of table bases\r
-                gui_send(GUI,"feature egt=\"nalimov\"");\r
-            }\r
-\r
-            if (uci_option_exist(Uci,"UCI_Chess960")) {\r
-                               gui_send(GUI,"feature variants=\"normal,fischerandom\"");\r
-                       } else {\r
-                               gui_send(GUI,"feature variants=\"normal\"");\r
-                       }\r
-            gui_send(GUI,"feature done=1"); // moved from engine_step\r
-\r
-            \r
-                //if (Uci->ready) xboard_send(XBoard,"feature done=1");\r
-\r
-                       // otherwise "feature done=1" will be sent when the engine is ready\r
+            send_xboard_options();\r
 \r
                } else if (match(string,"quit")) {\r
                        my_log("POLYGLOT *** \"quit\" from GUI ***\n");\r
@@ -588,6 +541,22 @@ static void xboard_step(char string[]) {
 \r
                        gui_send(GUI,"Error (unknown command): %s",string);\r
 \r
+        } else if (match(string,"option *=*")){\r
+            char *name=Star[0];\r
+            char *value=Star[1];\r
+            if(match(name, "Polyglot *")){\r
+                char *pg_name=Star[0];\r
+                polyglot_set_option(pg_name,value);\r
+            }else{\r
+                start_protected_command();\r
+                engine_send(Engine,"setoption name %s value %s",name,value);\r
+                end_protected_command();\r
+            }\r
+        } else if (match(string,"option *")){\r
+            char *name=Star[0];\r
+            start_protected_command();\r
+            engine_send(Engine,"setoption name %s",name);\r
+            end_protected_command();\r
         } else if (XB->has_feature_smp && match(string,"cores *")){\r
                 int cores=atoi(Star[0]);\r
                 if(cores>=1){\r
@@ -845,6 +814,125 @@ static void engine_step(char string[]) {
                }\r
 }\r
 \r
+// format_xboard_option_line\r
+\r
+void format_xboard_option_line(char * option_line, option_t *opt){\r
+    int j;\r
+    char option_string[StringSize];\r
+    strcpy(option_line,"");\r
+    strcat(option_line,"feature option=\"");\r
+    if(opt->mode&PG){\r
+        strcat(option_line,"Polyglot ");\r
+    }\r
+    sprintf(option_string,"%s",opt->name);\r
+    strcat(option_line,option_string);\r
+    sprintf(option_string," -%s",opt->type);\r
+    strcat(option_line,option_string);\r
+    if(strcmp(opt->type,"button") && strcmp(opt->type,"combo")){\r
+        if(strcmp(opt->type,"check")){\r
+            sprintf(option_string," %s",opt->default_);\r
+        }else{\r
+            sprintf(option_string," %d",\r
+                    strcmp(opt->default_,"true")?0:1);\r
+        }\r
+        strcat(option_line,option_string);\r
+    }\r
+    if(!strcmp(opt->type,"spin")){\r
+        sprintf(option_string," %s",opt->min);\r
+            strcat(option_line,option_string);\r
+    }\r
+    if(!strcmp(opt->type,"spin")){\r
+        sprintf(option_string," %s",opt->max);\r
+        strcat(option_line,option_string);\r
+    }\r
+    for(j=0;j<opt->var_nb;j++){\r
+        if(!strcmp(opt->var[j],opt->default_)){\r
+            sprintf(option_string," *%s",opt->var[j]);\r
+        }else{\r
+            sprintf(option_string," %s",opt->var[j]);\r
+        }\r
+        strcat(option_line,option_string);\r
+        if(j!=opt->var_nb-1){\r
+            strcat(option_line," ///");\r
+        }\r
+    }\r
+    strcat(option_line,"\"");\r
+}\r
+\r
+// send_xboard_options\r
+\r
+static void send_xboard_options(){\r
+    int i;\r
+    char option_line[StringSize]="";\r
+    option_t *p=Option;\r
+    const char * name;\r
+    XB->proto_ver = atoi(Star[0]);\r
+    ASSERT(XB->proto_ver>=2);\r
+    \r
+    gui_send(GUI,"feature done=0");\r
+    \r
+    gui_send(GUI,"feature analyze=1");\r
+    gui_send(GUI,"feature colors=0");\r
+    gui_send(GUI,"feature draw=1");\r
+    gui_send(GUI,"feature ics=1");\r
+    gui_send(GUI,"feature myname=\"%s\"",option_get_string("EngineName"));\r
+    gui_send(GUI,"feature name=1");\r
+    gui_send(GUI,"feature pause=0");\r
+    gui_send(GUI,"feature ping=1");\r
+    gui_send(GUI,"feature playother=1");\r
+    gui_send(GUI,"feature reuse=1");\r
+    gui_send(GUI,"feature san=0");\r
+    gui_send(GUI,"feature setboard=1");\r
+    gui_send(GUI,"feature sigint=0");\r
+    gui_send(GUI,"feature sigterm=0");\r
+    gui_send(GUI,"feature time=1");\r
+    gui_send(GUI,"feature usermove=1");\r
+    if (XB->has_feature_memory){\r
+        gui_send(GUI,"feature memory=1");\r
+    }else{\r
+        gui_send(GUI,"feature memory=0");\r
+    }\r
+    if (XB->has_feature_smp){\r
+        gui_send(GUI,"feature smp=1");\r
+    }else{\r
+        gui_send(GUI,"feature smp=0");\r
+    }\r
+    if (XB->has_feature_egt){\r
+            // TODO: support for other types of table bases\r
+        gui_send(GUI,"feature egt=\"nalimov\"");\r
+    }else{\r
+        gui_send(GUI,"feature egt=\"\"");\r
+    }\r
+    \r
+    if (uci_option_exist(Uci,"UCI_Chess960")) {\r
+        gui_send(GUI,"feature variants=\"normal,fischerandom\"");\r
+    } else {\r
+        gui_send(GUI,"feature variants=\"normal\"");\r
+    }\r
+    \r
+    for(i=0;i<Uci->option_nb;i++){\r
+        if(!strcmp(Uci->option[i].name,PolyglotBookFile)) continue;\r
+        if(my_string_case_equal(Uci->option[i].name,"UCI_AnalyseMode")) continue;\r
+        if(my_string_case_equal(Uci->option[i].name,"Ponder")) continue;\r
+        if(my_string_case_equal(Uci->option[i].name,"Hash")) continue;\r
+        if(my_string_case_equal(Uci->option[i].name,"NalimovPath")) continue;\r
+        if((name=uci_thread_option(Uci))!=NULL && my_string_case_equal(Uci->option[i].name,name)) continue;\r
+        format_xboard_option_line(option_line,Uci->option+i);\r
+\r
+        gui_send(GUI,"%s",option_line);\r
+\r
+    }\r
+    while(p->name){\r
+        if(p->mode &XBOARD){\r
+            format_xboard_option_line(option_line,p);\r
+            gui_send(GUI,"%s",option_line);\r
+        }\r
+        p++;\r
+    }       \r
+    gui_send(GUI,"feature done=1"); \r
+    \r
+}\r
+\r
 // comp_move()\r
 \r
 static void comp_move(int move) {\r