X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=proce.c;h=db64ef330ddc670aa93ecd9b3fe2ecb6d05054de;hb=26d4bd0e336dd729589dbec58ad12e3e50a7e2b6;hp=6538fb9997c0749c229108539fb2327ff1aeec4e;hpb=2945d63eec617a4411287ceda774a1e0186fc350;p=bonanza.git diff --git a/proce.c b/proce.c index 6538fb9..db64ef3 100644 --- a/proce.c +++ b/proce.c @@ -58,7 +58,7 @@ static int CONV cmd_thread( char **lasts ); #endif #if defined(MPV) -static int CONV cmd_mpv( char **lasts ); +static int CONV cmd_mpv( tree_t * restrict ptree, char **lasts ); #endif #if defined(DFPN) @@ -90,7 +90,11 @@ static int CONV cmd_move( tree_t * restrict ptree, char **lasts ); static int CONV cmd_new( tree_t * restrict ptree, char **lasts ); 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 ) @@ -122,11 +126,15 @@ procedure( tree_t * restrict ptree ) return proce_cui( ptree ); } +char *start_pos, start_data[512]; // [HGM] undo: for remembering start position +int move_list[1024], move_ptr; + #ifdef XBOARD #define IF(X) else if(!strcmp(command, X)) int myTime, hisTime, movesPerSession, inc, plyNr; char xboard_mode; +char analyze_mode; static void SetTimes(void) @@ -152,8 +160,14 @@ proce_xboard(char *line, const char *command, tree_t * restrict ptree) sscanf(line + strlen(command) + 1, "%d", &value); Out("# command = '%s'\n", line); if(0) ; - IF("protover") { Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER - "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n"); } + IF("protover") { +#if defined(MPV) + Out("feature option=\"MultiPV -spin 1 1 100\"\n"); + Out("feature option=\"centi-Pawn margin -spin 200 0 25000\"\n"); +#endif + Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER + "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n"); + } IF("new") { forceMode = plyNr = 0; SetTimes(); return 0; } IF("easy") { strcpy(line, "ponder off"); return 0; } IF("hard") { strcpy(line, "ponder on"); return 0; } @@ -168,11 +182,14 @@ 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") { ; } + IF("option") { + if(sscanf(line+7, "MultiPV=%d", &value) == 1) { sprintf(line, "mpv num %d", value); return 0; } + if(sscanf(line+7, "centi-Pawn margin=%d", &value) == 1) { sprintf(line, "mpv width %d", value); return 0; } + } IF("level") { int min, sec; float fsec=0.; if(sscanf(line+6, "%d %d:%d %f", &movesPerSession, &min, &sec, &fsec) != 4) sscanf(line+6, "%d %d %f", &movesPerSession, &min, &fsec); @@ -181,7 +198,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 @@ -200,9 +217,10 @@ Out("# from=%d\n",from); sprintf(line, "%c%c%c%c%s", 'a'+'9'-fromX, '1'+'9'-fromY, 'a'+'9'-toX, '1'+'9'-toY, astr_table_piece[abs(BOARD[from]) + (promo == '+' ? promote : 0)]); } - plyNr++; return 0; + plyNr++; + return 0; } - IF("undo") { ; } + IF("undo") { return 0; } IF("remove") { ; } IF("ping") { Out("pong %d\n", value); } return 1; @@ -227,6 +245,14 @@ 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 +#if defined(MPV) + if ( ! strcmp( token, "mpv" ) ) { return cmd_mpv( ptree, &last ); } +#endif + 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); } @@ -234,7 +260,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 ); } @@ -255,9 +280,6 @@ static int CONV proce_cui( tree_t * restrict ptree ) #if defined(MNJ_LAN) if ( ! strcmp( token, "mnj" ) ) { return cmd_mnj( &last ); } #endif -#if defined(MPV) - if ( ! strcmp( token, "mpv" ) ) { return cmd_mpv( &last ); } -#endif #if defined(DFPN) if ( ! strcmp( token, "dfpn" ) ) { return cmd_dfpn( ptree, &last ); } #endif @@ -496,6 +518,71 @@ cmd_mnjmove( tree_t * restrict ptree, char **lasts, int num_alter ) #endif +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; + char *p = start_data; + if( move_ptr <= 0 ) { + str_error = "undo past start of game ignored"; + return -2; + } + + AbortDifficultCommand; + + last--; + cmd_new( ptree, &p ); + 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; } @@ -1420,6 +1519,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; } @@ -1435,8 +1536,11 @@ static int CONV cmd_new( tree_t * restrict ptree, char **lasts ) AbortDifficultCommand; + start_pos = *lasts; move_ptr = 0; // [HGM] undo: remember start position + if ( str1 != NULL ) { + strncpy(start_data, str1, 511); // [HGM] undo: remember start position memset( &min_posi.asquare, empty, nsquare ); min_posi.hand_black = min_posi.hand_white = 0; iret = read_board_rep1( str1, &min_posi ); @@ -1779,7 +1883,7 @@ static int CONV cmd_learn( tree_t * restrict ptree, char **lasts ) #if defined(MPV) -static int CONV cmd_mpv( char **lasts ) +static int CONV cmd_mpv( tree_t * restrict ptree, char **lasts ) { const char *str = strtok_r( NULL, str_delimiters, lasts ); char *ptr; @@ -1809,6 +1913,8 @@ static int CONV cmd_mpv( char **lasts ) mpv_num = (int)l; + if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue changing num + return 1; } else if ( ! strcmp( str, "width" ) ) @@ -1830,6 +1936,8 @@ static int CONV cmd_mpv( char **lasts ) mpv_width = (int)l; + if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue after changing width + return 1; }