version 1.4.53b
[polyglot.git] / uci.c
diff --git a/uci.c b/uci.c
index 5eff8cc..dd13713 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -203,6 +203,8 @@ void uci_clear(uci_t * uci) {
    uci->root_move = MoveNone;\r
    uci->root_move_pos = 0;\r
    uci->root_move_nb = board_mobility(uci->board);\r
+\r
+   uci->multipvSP=0;\r
 }\r
 \r
 // uci_send_isready()\r
@@ -640,7 +642,7 @@ static int parse_info(uci_t * uci, const char string[]) {
          ASSERT(!my_string_empty(argument));\r
 \r
          n = atoi(argument);\r
-                if(Uci->multipv_mode) multipvline=n;\r
+        multipvline=n;\r
         \r
          ASSERT(n>=1);\r
 \r
@@ -733,16 +735,43 @@ static int parse_info(uci_t * uci, const char string[]) {
 \r
    parse_close(parse);\r
 \r
-   // update display\r
-   //lousy uci,filter out lower depth multipv lines that have been repeated from the engine \r
-   if(multipvline>1 && uci->depth<uci->best_depth) event &= ~EVENT_PV;\r
+\r
+   // code by HGM\r
    if ((event & EVENT_PV) != 0) {\r
       uci->best_score = uci->score; \r
-         uci->best_depth = uci->depth;\r
-         if(multipvline==1)uci->depth=-1; //HACK ,clears the engine outpout window,see send_pv in adapter.cpp \r
       uci->best_sel_depth = uci->sel_depth;\r
       line_copy(uci->best_pv,uci->pv);\r
    }\r
+   if(uci->depth < uci->best_depth){\r
+     // ignore lines of lower depth\r
+     event &= ~EVENT_PV;\r
+   } else {\r
+     if(uci->depth > uci->best_depth) {\r
+       // clear stack when we start new depth\r
+       uci->multipvSP = 0; \r
+     }\r
+     uci->best_depth = uci->depth;\r
+     if(multipvline >= 1) {\r
+       int i;\r
+       for(i=0; i<uci->multipvSP; i++) {\r
+        if(uci->score == uci->multipvScore[i] && uci->pv[0] == uci->multipvMove[i]) {\r
+          event &= ~EVENT_PV; // ignore duplicates\r
+        }\r
+       }\r
+       if(event & EVENT_PV){\r
+        // line is new, try to add to stack\r
+        if(uci->multipvSP<MultiPVStackSize){\r
+          uci->multipvMove[uci->multipvSP] = uci->pv[0];\r
+          uci->multipvScore[uci->multipvSP] = uci->score;\r
+          uci->multipvSP++;\r
+        }else{\r
+          my_fatal("parse_info(): multipv stack overflow.");\r
+        }\r
+       }\r
+     }\r
+   }\r
+\r
+\r
    return event;\r
 }\r
 \r