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 bool is_solution(int move, const board_t * board, const char bm[], const char am[]) { char move_string[256]; bool correct; ASSERT(move!=MoveNone); ASSERT(bm!=NULL); ASSERT(am!=NULL); if (!move_is_legal(move,board)) { board_disp(board); move_disp(move,board); printf("\n\n"); } ASSERT(move_is_legal(move,board)); if (!move_to_san(move,board,move_string,256)) ASSERT(false); correct = false; if (!my_string_empty(bm)) { correct = string_contain(bm,move_string); } else if (!my_string_empty(am)) { correct = !string_contain(am,move_string); } else { ASSERT(false); } return correct; }
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(); }
void disp_win(t_env *e, int player) { board_disp(e); if (player == HUMAN) ft_putendl("___ You win ! ___"); if (player == AI) ft_putendl("___ Computer wins ! ___"); if (player == NONE) ft_putendl("___ No winner ! ___"); }
void game_disp(const game_t * game) { board_t board[1]; int i, move; ASSERT(game_is_ok(game)); board_copy(board,game->start_board); board_disp(board); for (i = 0; i < game->pos; i++) { move = game->move[i]; move_disp(move,board); move_do(board,move); } my_log("POLYGLOT\n"); board_disp(board); }
int turn_ia(t_env *e) { board_insert(e, minimax(e, MAX_DEPTH), 2); e->counter_ai--; if (check_win(e, 2) == 1) { disp_win(e, AI); return (1); } if (board_complete(e) == 1 || (e->counter_ai == 0 && e->counter_hu == 0 && check_win(e, 2) == 0)) { disp_win(e, NONE); return (1); } board_disp(e); return (0); }
int turn_player(t_env *e) { get_input(e); board_insert(e, e->input, 1); e->counter_hu--; if (check_win(e, 1) == 1) { disp_win(e, HUMAN); return (1); } if (board_complete(e) == 1 || (e->counter_ai == 0 && e->counter_hu == 0 && check_win(e, 1) == 0)) { disp_win(e, NONE); return (1); } board_disp(e); return (0); }
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; }
int game_loop(t_env *e) { int random; srand(time(NULL)); random = (rand() % 2); board_disp(e); if (random) { turn_player(e); turn_ia(e); } else turn_ia(e); while (1) { if (turn_player(e) == 1) return (0); if (turn_ia(e) == 1) return (0); } return (0); }
void search_perft(const board_t * board, int depth_max) { int depth; my_timer_t timer[1]; double time, speed; ASSERT(board_is_ok(board)); ASSERT(depth_max>=1&&depth_max<DepthMax); // init board_disp(board); // iterative deepening for (depth = 1; depth <= depth_max; depth++) { // init NodeNb = 0; LeafNb = 0; my_timer_reset(timer); my_timer_start(timer); perft(board,depth); my_timer_stop(timer); time = my_timer_elapsed_cpu(timer); speed = (time < 0.01) ? 0.0 : double(NodeNb) / time; printf("%2d %10lld %10lld %7.2f %7.0f\n",depth,NodeNb,LeafNb,time,speed); } printf("\n"); }
void xboard2uci_engine_step(char string[]) { int event; board_t board[1]; event = uci_parse(Uci,string); // react to events if ((event & EVENT_READY) != 0) { // the engine is now ready if (!Uci->ready) { Uci->ready = TRUE; // if (XB->proto_ver >= 2) xboard_send(XBoard,"feature done=1"); } if (!DelayPong && XB->ping >= 0) { gui_send(GUI,"pong %d",XB->ping); XB->ping = -1; } } if ((event & EVENT_MOVE) != 0 && State->state == THINK) { // the engine is playing a move // MEGA HACK: estimate remaining time because XBoard won't send it! my_timer_stop(State->timer); XB->my_time -= my_timer_elapsed_real(State->timer); XB->my_time += XB->inc; if (XB->mps != 0 && (game_move_nb(Game) + 1) % XB->mps == 0) XB->my_time += XB->base; if (XB->my_time < 0.0) XB->my_time = 0.0; // make sure to remember the ponder move State->hint_move=Uci->ponder_move; // play the engine move comp_move(Uci->best_move); } if ((event & EVENT_PV) != 0) { // the engine has sent a new PV send_pv(); } if ((event & EVENT_INFO) != 0) { // the engine has sent info send_info(); } if((event & (EVENT_DRAW|EVENT_RESIGN))!=0){ my_log("POYGLOT draw offer/resign from engine\n"); if(option_find(Uci->option,"UCI_DrawOffers")){ if(event & EVENT_DRAW) gui_send(GUI,"offer draw"); else gui_send(GUI,"resign"); } } if(((event & EVENT_ILLEGAL_MOVE)!=0) && (State->state == THINK)){ game_get_board(Game,board); if(board->turn==White){ gui_send(GUI,"0-1 {polyglot: resign" " (illegal engine move by white: %s)}",Uci->bestmove); }else{ gui_send(GUI,"1-0 {polyglot: resign" " (illegal engine move by black: %s)}",Uci->bestmove); } board_disp(board); XB->result = TRUE; mess(); } }