version 1.4.50b
[polyglot.git] / uci.c
diff --git a/uci.c b/uci.c
index 03c6647..5eff8cc 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -10,6 +10,7 @@
 \r
 #include "board.h"\r
 #include "engine.h"\r
+#include "gui.h"\r
 #include "move.h"\r
 #include "move_do.h"\r
 #include "move_legal.h"\r
@@ -18,6 +19,7 @@
 #include "line.h"\r
 #include "uci.h"\r
 \r
+\r
 // constants\r
 \r
 static const bool UseDebug = FALSE;\r
@@ -58,6 +60,29 @@ static int  mate_score     (int dist);
 \r
 // functions\r
 \r
+\r
+// uci_adapt_UCI3()\r
+\r
+static void apply_UCI3_heuristics(option_t *opt){\r
+  if(option_get_int(Option,"UCIVersion")>2){\r
+    return;\r
+  }\r
+  if(!my_string_equal(opt->type,"string")){\r
+    return;\r
+  }\r
+  if(!strncmp(opt->name,"UCI_",4)){\r
+    return;\r
+  }\r
+  if(my_string_case_contains(opt->name,"file")){\r
+    my_string_set(&opt->type,"file");\r
+    return;\r
+  }\r
+  if(my_string_case_contains(opt->name,"path")){\r
+    my_string_set(&opt->type,"path");\r
+    return;\r
+  }\r
+}\r
+\r
 // uci_set_threads()\r
 \r
 void uci_set_threads(uci_t * uci, int n) {\r
@@ -125,6 +150,11 @@ void uci_open(uci_t * uci, engine_t * engine) {
 \r
    do {\r
       engine_get(uci->engine,string);\r
+      // Handle the case that the engine is really a WB engine somewhat gracefully.\r
+      if((strstr(string,"Illegal") || strstr(string,"Error"))\r
+         &&strstr(string,"uci")){\r
+          my_fatal("uci_open(): Not an UCI engine (not found).\n");\r
+      }\r
       event = uci_parse(uci,string);\r
    } while (!engine_eof(Engine) && (event & EVENT_UCI) == 0);\r
 }\r
@@ -271,7 +301,7 @@ bool uci_send_option(uci_t * uci, const char option[], const char format[], ...)
    opt=option_find(uci->option,option);\r
    if(opt){\r
        found=TRUE;\r
-       if(!my_string_case_equal(opt->type,"button")){\r
+       if(!IS_BUTTON(opt->type)){\r
            if(!my_string_equal(opt->value,value)){\r
                engine_send(uci->engine,"setoption name %s value %s",\r
                            opt->name,value);\r
@@ -308,7 +338,7 @@ int uci_parse(uci_t * uci, const char string[]) {
    parse_open(parse,string);\r
 \r
    if (parse_get_word(parse,command,StringSize)) {\r
-\r
+       \r
       parse_get_string(parse,argument,StringSize);\r
       if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" ARGUMENT \"%s\"\n",command,argument);\r
 \r
@@ -805,6 +835,8 @@ static void parse_option(uci_t * uci, const char string[]) {
    }\r
 \r
    parse_close(parse);\r
+\r
+   apply_UCI3_heuristics(opt);\r
    option_insert(uci->option,opt);\r
    option_free(opt);\r
 \r