bool line_from_can (move_t line[], const board_t * board, const char string[], int size) { int pos; char new_string[StringSize], *p; int move; board_t new_board[1]; ASSERT(line!=NULL); ASSERT(board_is_ok(board)); ASSERT(string!=NULL); ASSERT(size>=LineSize); // init pos = 0; board_copy(new_board,board); // loop strcpy(new_string,string); // HACK for (p = strtok(new_string," "); p != NULL; p = strtok(NULL," ")) { move = move_from_can(p,new_board); ASSERT(move!=MoveNone); ASSERT(move_is_legal(move,new_board)); if (move == MoveNone || !move_is_legal(move,new_board)) break; // HACK: ignore illegal moves if (pos >= size) return false; line[pos++] = move; move_do(new_board,move); } if (pos >= size) return false; line[pos] = MoveNone; return true; }
static int parse_info(uci_t * uci, const char string[]) { int event; parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; int n; int multipvline=0; sint64 ln; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init event = EVENT_NONE; strcpy(command,"info"); parse_open(parse,string); parse_add_keyword(parse,"cpuload"); parse_add_keyword(parse,"currline"); parse_add_keyword(parse,"currmove"); parse_add_keyword(parse,"currmovenumber"); parse_add_keyword(parse,"depth"); parse_add_keyword(parse,"hashfull"); parse_add_keyword(parse,"multipv"); parse_add_keyword(parse,"nodes"); parse_add_keyword(parse,"nps"); parse_add_keyword(parse,"pv"); parse_add_keyword(parse,"refutation"); parse_add_keyword(parse,"score"); parse_add_keyword(parse,"seldepth"); parse_add_keyword(parse,"string"); parse_add_keyword(parse,"tbhits"); parse_add_keyword(parse,"time"); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"cpuload")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->cpu = double(n) / 1000.0; } else if (my_string_equal(option,"currline")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->current_line,uci->board,argument,LineSize); } else if (my_string_equal(option,"currmove")) { ASSERT(!my_string_empty(argument)); uci->root_move = move_from_can(argument,uci->board); ASSERT(uci->root_move!=MoveNone); } else if (my_string_equal(option,"currmovenumber")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1&&n<=uci->root_move_nb); if (n >= 1 && n <= uci->root_move_nb) { uci->root_move_pos = n - 1; ASSERT(uci->root_move_pos>=0&&uci->root_move_pos<uci->root_move_nb); } } else if (my_string_equal(option,"depth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=1); if (n >= 0) { if (n > uci->depth) event |= EVENT_DEPTH; uci->depth = n; } } else if (my_string_equal(option,"hashfull")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->hash = double(n) / 1000.0; } else if (my_string_equal(option,"multipv")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); if(Uci->multipv_mode) multipvline=n; ASSERT(n>=1); } else if (my_string_equal(option,"nodes")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); if (ln >= 0) uci->node_nb = ln; } else if (my_string_equal(option,"nps")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->speed = double(n); } else if (my_string_equal(option,"pv")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); event |= EVENT_PV; } else if (my_string_equal(option,"refutation")) { ASSERT(!my_string_empty(argument)); line_from_can(uci->pv,uci->board,argument,LineSize); } else if (my_string_equal(option,"score")) { ASSERT(!my_string_empty(argument)); parse_score(uci,argument); } else if (my_string_equal(option,"seldepth")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->sel_depth = n; } else if (my_string_equal(option,"string")) { if(!strncmp(argument,"DrawOffer",9)) event |= EVENT_DRAW; if(!strncmp(argument,"Resign",6)) event |= EVENT_RESIGN; // TODO: argument to EOS ASSERT(!my_string_empty(argument)); } else if (my_string_equal(option,"tbhits")) { ASSERT(!my_string_empty(argument)); ln = my_atoll(argument); ASSERT(ln>=0); } else if (my_string_equal(option,"time")) { ASSERT(!my_string_empty(argument)); n = atoi(argument); ASSERT(n>=0); if (n >= 0) uci->time = double(n) / 1000.0; } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); // update display //lousy uci,filter out lower depth multipv lines that have been repeated from the engine if(multipvline>1 && uci->depth<uci->best_depth) event &= ~EVENT_PV; 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); } return event; }
static int parse_bestmove(uci_t * uci, const char string[]) { parse_t parse[1]; char command[StringSize]; char option[StringSize]; char argument[StringSize]; board_t board[1]; ASSERT(uci_is_ok(uci)); ASSERT(string!=NULL); // init strcpy(command,"bestmove"); parse_open(parse,string); parse_add_keyword(parse,"ponder"); // bestmove if (!parse_get_string(parse,argument,StringSize)) { my_fatal("parse_bestmove(): missing argument\n"); } uci->best_move = move_from_can(argument,uci->board); if (uci->best_move == MoveNone) my_fatal("parse_bestmove(): not a move \"%s\"\n",argument); ASSERT(uci->best_move!=MoveNone); ASSERT(move_is_legal(uci->best_move,uci->board)); // loop while (parse_get_word(parse,option,StringSize)) { parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" OPTION \"%s\" ARGUMENT \"%s\"\n",command,option,argument); if (false) { } else if (my_string_equal(option,"ponder")) { ASSERT(!my_string_empty(argument)); board_copy(board,uci->board); move_do(board,uci->best_move); uci->ponder_move = move_from_can(argument,board); // if (uci->ponder_move == MoveNone) my_fatal("parse_bestmove(): not a move \"%s\"\n",argument); ASSERT(uci->ponder_move!=MoveNone); ASSERT(move_is_legal(uci->ponder_move,board)); } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); } } parse_close(parse); return EVENT_MOVE; }
void search(const board_t * board, int depth_max, double time_max) { char string[256]; ASSERT(board_is_ok(board)); ASSERT(depth_max>=1&&depth_max<DepthMax); ASSERT(time_max>=0.0); // engine Depth = 0; BestMove = MoveNone; BestValue = 0; line_clear(BestPV); NodeNb = 0; LeafNb = 0; Time = 0.0; Move = MoveNone; MovePos = 0; MoveNb = 0; // init uci_send_ucinewgame(Uci); uci_send_isready_sync(Uci); // position if (!board_to_fen(board,string,256)) ASSERT(false); engine_send(Engine,"position fen %s",string); // search engine_send_queue(Engine,"go"); engine_send_queue(Engine," movetime %.0f",time_max*1000.0); engine_send_queue(Engine," depth %d",depth_max); engine_send(Engine,""); // newline // wait for feed-back while (true) { engine_get(Engine,string,256); if (false) { } else if (match(string,"bestmove * ponder *")) { BestMove = move_from_can(Star[0],board); ASSERT(BestMove!=MoveNone&&move_is_legal(BestMove,board)); break; } else if (match(string,"bestmove *")) { BestMove = move_from_can(Star[0],board); ASSERT(BestMove!=MoveNone&&move_is_legal(BestMove,board)); break; } } printf("\n"); }