From: H.G. Muller Date: Fri, 13 Sep 2013 15:49:44 +0000 (+0200) Subject: Implement analyze command X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=c61aaabe5b3091a918cd4763e455e3b848d51a54;p=bonanza.git Implement analyze command To implement infinite analysis, the 'analyze' and 'exit' commands are added. A search with flag_ponder set is used to do the analysis. When in analyze mode, such a search will be automatically restarted after receiving a move or undo command. --- diff --git a/proce.c b/proce.c index 3de4d5e..1aab235 100644 --- a/proce.c +++ b/proce.c @@ -92,6 +92,9 @@ static int CONV cmd_read( tree_t * restrict ptree, char **lasts ); static int CONV cmd_resign( tree_t * restrict ptree, char **lasts ); static int CONV cmd_undo( tree_t * restrict ptree ); // [HGM] undo static int CONV cmd_time( char **lasts ); +static int CONV cmd_undo( tree_t * restrict ptree ); // [HGM] undo +static int CONV cmd_analyze( tree_t * restrict ptree ); // [HGM] analyze +static int CONV cmd_exit( void ); int CONV is_move( const char *str ) @@ -131,6 +134,7 @@ int move_list[1024], move_ptr; int myTime, hisTime, movesPerSession, inc, plyNr; char xboard_mode; +char analyze_mode; static void SetTimes(void) @@ -172,8 +176,8 @@ Out("# command = '%s'\n", line); IF("sd") { sprintf(line, "limit depth %d", value); return 0; } IF("st") { ; } IF("quit") { return 0; } - IF("analyze") { ; } - IF("exit") { ; } + IF("analyze") { return 0; } + IF("exit") { return 0; } IF("variant") { /* ignore, since it must be Shogi */; } IF("setboard") { ; } IF("option") { ; } @@ -185,7 +189,7 @@ Out("# command = '%s'\n", line); IF("usermove") { char fromX=line[9], fromY=line[10], toX=line[11], toY=line[12], promo=line[13]; int from; {int i,j;for(i=0;i<81;i+=9){printf("# ");for(j=0;j<9;j++)printf(" %3d", BOARD[i+j]);printf("\n");}} - if(forceMode) strcpy(line, "move "), line += 5; else plyNr++, SetTimes(); + if(forceMode || analyze_mode) strcpy(line, "move "), line += 5; else plyNr++, SetTimes(); if(fromY == '@') { // drop if(fromX >= 'a') fromX += 'A' - 'a'; switch(fromX) { // encode piece @@ -207,7 +211,7 @@ Out("# from=%d\n",from); plyNr++; return 0; } - IF("undo") { ; } + IF("undo") { return 0; } IF("remove") { ; } IF("ping") { Out("pong %d\n", value); } return 1; @@ -232,7 +236,11 @@ static int CONV proce_cui( tree_t * restrict ptree ) if ( ! strcmp( token, "xboard" ) ) { xboard_mode = 1; game_status |= flag_noprompt; return 1; } } #endif + if ( ! strcmp( token, "analyze" ) ) { return cmd_analyze( ptree ); } // [HGM] analyze + if ( ! strcmp( token, "exit" ) ) { return cmd_exit(); } // [HGM] analyze + if ( ! strcmp( token, "move" ) ) { return cmd_move( ptree, &last ); } if ( ! strcmp( token, "undo" ) ) { return cmd_undo( ptree ); } // [HGM] undo + analyze_mode = 0; // [HGM] analyze: all other commands terminate analysis if ( is_move( token ) ) { return cmd_usrmove( ptree, token, &last ); } if ( ! strcmp( token, "s" ) ) { return cmd_move_now(); } if ( ! strcmp( token, "beep" ) ) { return cmd_beep( &last); } @@ -240,7 +248,6 @@ static int CONV proce_cui( tree_t * restrict ptree ) if ( ! strcmp( token, "display" ) ) { return cmd_display( ptree, &last ); } if ( ! strcmp( token, "hash" ) ) { return cmd_hash( &last ); } if ( ! strcmp( token, "limit" ) ) { return cmd_limit( &last ); } - if ( ! strcmp( token, "move" ) ) { return cmd_move( ptree, &last ); } if ( ! strcmp( token, "new" ) ) { return cmd_new( ptree, &last ); } if ( ! strcmp( token, "outmove" ) ) { return cmd_outmove( ptree ); } if ( ! strcmp( token, "peek" ) ) { return cmd_peek( &last ); } @@ -503,6 +510,22 @@ cmd_mnjmove( tree_t * restrict ptree, char **lasts, int num_alter ) static int CONV +do_analyze( tree_t * restrict ptree ) +{ // [HGM] analyze: do a ponder search on the current position + int iret; + if ( get_elapsed( &time_start ) < 0 ) { return -1; } + time_limit = time_max_limit = 1e9; // kludge: use huge time to mimic infinity +#ifdef XBOARD + if(xboard_mode) Out("1 0 0 0 New Search\n"); // make sure lower depth is emitted, so XBoard undestand new search started +#endif + game_status |= flag_pondering; + iret = iterate( ptree ); + game_status &= ~flag_pondering; + return iret; +} + + +static int CONV cmd_undo( tree_t * restrict ptree ) { // [HGM] undo: restart the game, and feed all moves except the last int i, last = move_ptr; @@ -519,6 +542,34 @@ cmd_undo( tree_t * restrict ptree ) for(i=0; i= 1 && *ptr == '\0' ) { + if ( analyze_mode ) // [HGM] analyze: in analysis mode we cannot set the engine thinking + { + str_error = str_bad_cmdline; + return -2; + } + for ( i = 0; i < l; i += 1 ) { if ( game_status & ( flag_move_now | mask_game_end ) ) { break; } @@ -1447,6 +1510,8 @@ static int CONV cmd_move( tree_t * restrict ptree, char **lasts ) str = strtok_r( NULL, str_delimiters, lasts ); } while ( str != NULL ); + + if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue after feeding moves return 1; } diff --git a/readme.txt b/readme.txt index 4754a5a..91ac240 100644 --- a/readme.txt +++ b/readme.txt @@ -366,6 +366,12 @@ directory to dump log files. 5. Command List --------------- +- analyze + Starts to ponder on the current position, until a command is + received. After a 'move' or 'undo' command pondering will continue + in the new position. To get out of this mode without side effects, + you can use the 'exit' command. + - beep on - beep off These commands enable (on) or disable (off) a beep when Bonanza