static void move_step(int move) { board_t board[1]; char move_string[256]; ASSERT(move_is_ok(move)); // log game_get_board(Game,board); if (move != MoveNone && move_is_legal(move,board)) { move_to_san(move,board,move_string,256); my_log("POLYGLOT MOVE %s\n",move_string); } else { move_to_can(move,board,move_string,256); my_log("POLYGLOT ILLEGAL MOVE \"%s\"\n",move_string); board_disp(board); my_fatal("move_step(): illegal move \"%s\"\n",move_string); } // play the move game_add_move(Game,move); board_update(); }
static void move_step(int move) { board_t board[1]; char move_string[256]; ASSERT(move_is_ok(move)); // log game_get_board(Game,board); if (XB->ics || (move != MoveNone && move_is_legal(move,board))) { move_to_san(move,board,move_string,sizeof(move_string)); my_log("POLYGLOT MOVE %s\n",move_string); } else { move_to_can(move,board,move_string,sizeof(move_string)); my_log("POLYGLOT ILLEGAL MOVE \"%s\"\n",move_string); board_disp(board); //since we have threads my_fatal is not enough,1 thread will wait for xboard to end the game //stuff illegal move in the comment as well,not everybody logs all the time. if(board->turn==White) xboard_send(XBoard,"0-1 {polyglot: %s illegal engine move white}\n",move_string); else xboard_send(XBoard,"1-0 {polyglot: %s illegal engine move black}\n",move_string); my_fatal("move_step(): illegal move \"%s\"\n",move_string); } // play the move game_add_move(Game,move); //board_update(); }
static void comp_move(int move) { board_t board[1]; char string[256]; ASSERT(move_is_ok(move)); ASSERT(State->state==THINK); ASSERT(!XB->analyse); if(option_get_bool(Option,"RepeatPV")) send_pv(); // to update time and nodes // send the move game_get_board(Game,board); if (move_is_castle(move,board) && option_get_bool(Option,"Chess960")) { if (!move_to_san(move,board,string,256)) my_fatal("comp_move(): move_to_san() failed\n"); // O-O/O-O-O } else { if (!move_to_can(move,board,string,256)) my_fatal("comp_move(): move_to_can() failed\n"); } gui_send(GUI,"move %s",string); // resign? if (option_get_bool(Option,"Resign") && Uci->root_move_nb > 1) { if (Uci->best_score <= -abs(option_get_int(Option,"ResignScore"))) { State->resign_nb++; my_log("POLYGLOT %d move%s with resign score\n",State->resign_nb,(State->resign_nb>1)?"s":""); if (State->resign_nb >= option_get_int(Option,"ResignMoves")) { my_log("POLYGLOT *** RESIGN ***\n"); gui_send(GUI,"resign"); } } else { if (State->resign_nb > 0) my_log("POLYGLOT resign reset (State->resign_nb=%d)\n",State->resign_nb); State->resign_nb = 0; } } // play the move move_step(move); no_mess(move); }
void list_disp(const list_t * list, const board_t * board) { int i, move, value; char string[256]; ASSERT(list_is_ok(list)); ASSERT(board_is_ok(board)); for (i = 0; i < list->size; i++) { move = list->move[i]; value = list->value[i]; if (!move_to_can(move,board,string,256)) ASSERT(false); my_log("POLYGLOT %-5s %04X %+4d\n",string,move,value); } my_log("POLYGLOT\n"); }
bool line_to_san(const move_t line[], const board_t * board, char string[], int size) { board_t new_board[1]; int pos; int move; char move_string[256]; ASSERT(line_is_ok(line)); ASSERT(board_is_ok(board)); ASSERT(string!=NULL); ASSERT(size>=StringSize); // init string[0]='\0'; if (size < StringSize) return false; // return false; board_copy(new_board,board); pos = 0; // loop while ((move = *line++) != MoveNone) { if (pos != 0) { if (pos >= size) return false; string[pos++] = ' '; } if (!move_is_legal(move,new_board) || !move_to_san(move,new_board,&string[pos],size-pos)) { if (Strict || UseDebug) { move_to_can(move,new_board,move_string,sizeof(move_string)); my_log("POLYGLOT ILLEGAL MOVE IN LINE %s\n",move_string); board_disp(new_board); if (Strict) my_fatal("line_to_san(): illegal move\n"); } break; } pos += (int)strlen(&string[pos]); move_do(new_board,move); } if (pos >= size) return false; string[pos] = '\0'; return true; }
bool line_to_can(const move_t line[], const board_t * board, char string[], int size) { board_t new_board[1]; int pos; int move; ASSERT(line_is_ok(line)); ASSERT(board_is_ok(board)); ASSERT(string!=NULL); ASSERT(size>=StringSize); // init if (size < StringSize) return false; board_copy(new_board,board); pos = 0; // loop while ((move = *line++) != MoveNone) { if (pos != 0) { if (pos >= size) return false; string[pos++] = ' '; } if (!move_to_can(move,new_board,&string[pos],size-pos)) return false; pos += (int)strlen(&string[pos]); move_do(new_board,move); } if (pos >= size) return false; string[pos] = '\0'; return true; }
static void send_board(int extra_move) { char fen[256]; int start, end; board_t board[1]; int pos; int move; char string[256]; ASSERT(extra_move==MoveNone||move_is_ok(extra_move)); ASSERT(!Uci->searching); // init game_get_board(Game,Uci->board); if (extra_move != MoveNone) move_do(Uci->board,extra_move); board_to_fen(Uci->board,fen,256); my_log("POLYGLOT FEN %s\n",fen); ASSERT(board_can_play(Uci->board)); // more init start = 0; end = game_pos(Game); ASSERT(end>=start); // position game_get_board(Game,board,start); board_to_fen(board,string,256); engine_send_queue(Engine,"position"); if (my_string_equal(string,StartFen)) { engine_send_queue(Engine," startpos"); } else { engine_send_queue(Engine," fen %s",string); } // move list if (end > start || extra_move != MoveNone) engine_send_queue(Engine," moves"); for (pos = start; pos < end; pos++) { // game moves move = game_move(Game,pos); move_to_can(move,board,string,256); engine_send_queue(Engine," %s",string); move_do(board,move); } if (extra_move != MoveNone) { // move to ponder on move_to_can(extra_move,board,string,256); engine_send_queue(Engine," %s",string); } // end engine_send(Engine,""); // newline }
static void comp_move(int move) { board_t board[1]; char string[256]; ASSERT(move_is_ok(move)); ASSERT(State->state==THINK); ASSERT(!XB->analyse); if(option_get_bool("RepeatPV")==true) send_pv(); // to update time and nodes // send the move game_get_board(Game,board); if (move_is_castle(move,board) && option_get_bool("Chess960")) { if (!move_to_san(move,board,string,sizeof(string))) my_fatal("comp_move(): move_to_san() failed\n"); // O-O/O-O-O } else { if (!move_to_can(move,board,string,sizeof(string))) my_fatal("comp_move(): move_to_can() failed\n"); } move_step(move); //game ended? if(game_status(Game)!= PLAYING){ //handle ics drawing stuff if(XB->ics){ switch (game_status(Game)){ case DRAW_MATERIAL: case DRAW_FIFTY: case DRAW_REPETITION: xboard_send(XBoard,"offer draw"); break; default: break; } } xboard_send(XBoard,"move %s",string); board_update(); no_mess(move); return; } // engine sended a move while in ponder mode? if(State->state==PONDER){ if(board->turn==White) xboard_send(XBoard,"0-1 {polyglot : engine moves while pondering}\n"); else xboard_send(XBoard,"1-0 {polyglot : engine moves while pondering}\n"); } // resign? if (option_get_bool("Resign") && Uci->root_move_nb > 1) { int best = Uci->best_score; if (option_get_bool("ScoreWhite") && colour_is_black(Uci->board->turn)) best = -best; if (best <= -abs(option_get_int("ResignScore"))) { State->resign_nb++; my_log("POLYGLOT %d move%s with resign score\n",State->resign_nb,(State->resign_nb>1)?"s":""); if (State->resign_nb >= option_get_int("ResignMoves")) { my_log("POLYGLOT *** RESIGN ***\n"); //send move and resign //xboard_send(XBoard,"move %s \nresign",string); //just resign xboard_send(XBoard,"resign",string); no_mess(move); return; } } else { if (State->resign_nb > 0) my_log("POLYGLOT resign reset (State->resign_nb=%d)\n",State->resign_nb); State->resign_nb = 0; } } no_mess(move); xboard_send(XBoard,"move %s",string); }