X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=uci.c;h=65d4d2a4f6c541415275b42af557af6758d772fd;hb=de010509fa0e57ba955da6512c714fbff8606af3;hp=9326ec7b27951712d929602f2142b8f5e0343a97;hpb=bb6c47f77f59067c358579a71cefa1ae65180a30;p=polyglot.git diff --git a/uci.c b/uci.c index 9326ec7..65d4d2a 100644 --- a/uci.c +++ b/uci.c @@ -10,6 +10,7 @@ #include "board.h" #include "engine.h" +#include "gui.h" #include "move.h" #include "move_do.h" #include "move_legal.h" @@ -18,6 +19,7 @@ #include "line.h" #include "uci.h" + // constants static const bool UseDebug = FALSE; @@ -148,6 +150,11 @@ void uci_open(uci_t * uci, engine_t * engine) { do { engine_get(uci->engine,string); + // Handle the case that the engine is really a WB engine somewhat gracefully. + if((strstr(string,"Illegal") || strstr(string,"Error")) + &&strstr(string,"uci")){ + my_fatal("uci_open(): Not an UCI engine.\n"); + } event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_UCI) == 0); } @@ -196,6 +203,8 @@ void uci_clear(uci_t * uci) { uci->root_move = MoveNone; uci->root_move_pos = 0; uci->root_move_nb = board_mobility(uci->board); + + uci->multipvSP=0; } // uci_send_isready() @@ -331,7 +340,7 @@ int uci_parse(uci_t * uci, const char string[]) { parse_open(parse,string); if (parse_get_word(parse,command,StringSize)) { - + parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" ARGUMENT \"%s\"\n",command,argument); @@ -633,7 +642,7 @@ static int parse_info(uci_t * uci, const char string[]) { ASSERT(!my_string_empty(argument)); n = atoi(argument); - if(Uci->multipv_mode) multipvline=n; + multipvline=n; ASSERT(n>=1); @@ -726,16 +735,43 @@ static int parse_info(uci_t * uci, const char string[]) { parse_close(parse); - // update display - //lousy uci,filter out lower depth multipv lines that have been repeated from the engine - if(multipvline>1 && uci->depthbest_depth) event &= ~EVENT_PV; + + // code by HGM if ((event & EVENT_PV) != 0) { uci->best_score = uci->score; - uci->best_depth = uci->depth; - if(multipvline==1)uci->depth=-1; //HACK ,clears the engine outpout window,see send_pv in adapter.cpp uci->best_sel_depth = uci->sel_depth; line_copy(uci->best_pv,uci->pv); } + if(uci->depth < uci->best_depth){ + // ignore lines of lower depth + event &= ~EVENT_PV; + } else { + if(uci->depth > uci->best_depth) { + // clear stack when we start new depth + uci->multipvSP = 0; + } + uci->best_depth = uci->depth; + if(multipvline >= 1) { + int i; + for(i=0; imultipvSP; i++) { + if(uci->score == uci->multipvScore[i] && uci->pv[0] == uci->multipvMove[i]) { + event &= ~EVENT_PV; // ignore duplicates + } + } + if(event & EVENT_PV){ + // line is new, try to add to stack + if(uci->multipvSPmultipvMove[uci->multipvSP] = uci->pv[0]; + uci->multipvScore[uci->multipvSP] = uci->score; + uci->multipvSP++; + }else{ + my_fatal("parse_info(): multipv stack overflow."); + } + } + } + } + + return event; }