9 /* unacceptable when the program is thinking, or quit pondering */
10 #define AbortDifficultCommand \
11 if ( game_status & flag_thinking ) \
13 str_error = str_busy_think; \
16 else if ( game_status & ( flag_pondering | flag_puzzling ) ) \
18 game_status |= flag_quit_ponder; \
23 # define CmdBook(x,y) cmd_book(y);
24 static int CONV cmd_book( char **lasts );
26 # define CmdBook(x,y) cmd_book(x,y);
27 static int CONV cmd_learn( tree_t * restrict ptree, char **lasts );
28 static int CONV cmd_book( tree_t * restrict ptree, char **lasts );
31 #if ! defined(NO_STDOUT)
32 static int CONV cmd_stress( char **lasts );
36 static int CONV proce_csalan( tree_t * restrict ptree );
37 static int CONV cmd_connect( tree_t * restrict ptree, char **lasts );
38 static int CONV cmd_sendpv( char **lasts );
42 static int CONV proce_mnj( tree_t * restrict ptree );
43 static int CONV cmd_mnjignore( tree_t *restrict ptree, char **lasts );
44 static int CONV cmd_mnj( char **lasts );
45 static int CONV cmd_mnjmove( tree_t * restrict ptree, char **lasts,
50 static int CONV proce_usi( tree_t * restrict ptree );
51 static int CONV usi_posi( tree_t * restrict ptree, char **lasts );
52 static int CONV usi_go( tree_t * restrict ptree, char **lasts );
53 static int CONV usi_ignore( tree_t * restrict ptree, char **lasts );
57 static int CONV cmd_thread( char **lasts );
61 static int CONV cmd_mpv( char **lasts );
65 static int CONV cmd_dfpn( tree_t * restrict ptree, char **lasts );
68 #if defined(DFPN_CLIENT)
69 static int CONV cmd_dfpn_client( tree_t * restrict ptree, char **lasts );
72 static int CONV proce_cui( tree_t * restrict ptree );
73 static int CONV cmd_usrmove( tree_t * restrict ptree, const char *str_move,
75 static int CONV cmd_outmove( tree_t * restrict ptree );
76 static int CONV cmd_move_now( void );
77 static int CONV cmd_ponder( char **lasts );
78 static int CONV cmd_limit( char **lasts );
79 static int CONV cmd_quit( void );
80 static int CONV cmd_beep( char **lasts );
81 static int CONV cmd_peek( char **lasts );
82 static int CONV cmd_stdout( char **lasts );
83 static int CONV cmd_newlog( char **lasts );
84 static int CONV cmd_hash( char **lasts );
85 static int CONV cmd_ping( void );
86 static int CONV cmd_suspend( void );
87 static int CONV cmd_problem( tree_t * restrict ptree, char **lasts );
88 static int CONV cmd_display( tree_t * restrict ptree, char **lasts );
89 static int CONV cmd_move( tree_t * restrict ptree, char **lasts );
90 static int CONV cmd_new( tree_t * restrict ptree, char **lasts );
91 static int CONV cmd_read( tree_t * restrict ptree, char **lasts );
92 static int CONV cmd_resign( tree_t * restrict ptree, char **lasts );
93 static int CONV cmd_undo( tree_t * restrict ptree ); // [HGM] undo
94 static int CONV cmd_time( char **lasts );
95 static int CONV cmd_undo( tree_t * restrict ptree ); // [HGM] undo
96 static int CONV cmd_analyze( tree_t * restrict ptree ); // [HGM] analyze
97 static int CONV cmd_exit( void );
100 int CONV is_move( const char *str )
102 if ( isdigit( (int)str[0] ) && isdigit( (int)str[1] )
103 && isdigit( (int)str[2] ) && isdigit( (int)str[3] )
104 && isupper( (int)str[4] ) && isupper( (int)str[5] )
105 && str[6] == '\0' ) { return 1; }
112 procedure( tree_t * restrict ptree )
115 if ( sckt_csa != SCKT_NULL ) { return proce_csalan( ptree ); }
119 if ( sckt_mnj != SCKT_NULL ) { return proce_mnj( ptree ); }
123 if ( usi_mode != usi_off ) { return proce_usi( ptree ); }
126 return proce_cui( ptree );
129 char *start_pos, start_data[512]; // [HGM] undo: for remembering start position
130 int move_list[1024], move_ptr;
133 #define IF(X) else if(!strcmp(command, X))
135 int myTime, hisTime, movesPerSession, inc, plyNr;
141 { // set white and black times from own and opponent time.
143 if(movesPerSession <= 0) moves = 35; else {
145 while(moves <= 0) moves += movesPerSession;
147 time_limit = (myTime-inc-30)/(moves+2) + inc;
148 time_max_limit = 3*time_limit;
149 if(time_max_limit > myTime - 30)time_max_limit = myTime - 30; // keep 0.3 sec margin, as Bonanza reads the clock infrequently
150 time_limit *= 10; // msec
151 time_max_limit *= 10;
152 Out("# moves=%d, time=%d inc=%d t=%d, max=%d\n", moves, myTime, inc, time_limit, time_max_limit);
156 proce_xboard(char *line, const char *command, tree_t * restrict ptree)
157 { // [HGM] added to make Bonanza.exe a native WinBoard engine
159 static char forceMode = 0;
160 sscanf(line + strlen(command) + 1, "%d", &value);
161 Out("# command = '%s'\n", line);
163 IF("protover") { Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER
164 "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n"); }
165 IF("new") { forceMode = plyNr = 0; SetTimes(); return 0; }
166 IF("easy") { strcpy(line, "ponder off"); return 0; }
167 IF("hard") { strcpy(line, "ponder on"); return 0; }
170 IF("time") { sscanf(line+5, "%d", &myTime); }
171 IF("otim") { sscanf(line+5, "%d", &hisTime); }
172 IF("force") { forceMode = 1; }
173 IF("go") { forceMode = 0; SetTimes(); plyNr++; strcpy(line, "move"); return 0; }
175 IF("cores") { sprintf(line, "tlp num %d", value); return 0; }
176 IF("sd") { sprintf(line, "limit depth %d", value); return 0; }
178 IF("quit") { return 0; }
179 IF("analyze") { return 0; }
180 IF("exit") { return 0; }
181 IF("variant") { /* ignore, since it must be Shogi */; }
184 IF("level") { int min, sec; float fsec=0.;
185 if(sscanf(line+6, "%d %d:%d %f", &movesPerSession, &min, &sec, &fsec) != 4)
186 sscanf(line+6, "%d %d %f", &movesPerSession, &min, &fsec);
187 min = 60*min + sec; myTime = hisTime = 100*min; inc = 100 * fsec;
189 IF("usermove") { char fromX=line[9], fromY=line[10], toX=line[11], toY=line[12], promo=line[13];
191 {int i,j;for(i=0;i<81;i+=9){printf("# ");for(j=0;j<9;j++)printf(" %3d", BOARD[i+j]);printf("\n");}}
192 if(forceMode || analyze_mode) strcpy(line, "move "), line += 5; else plyNr++, SetTimes();
193 if(fromY == '@') { // drop
194 if(fromX >= 'a') fromX += 'A' - 'a';
195 switch(fromX) { // encode piece
196 case 'P': fromX = pawn; break;
197 case 'L': fromX = lance; break;
198 case 'N': fromX = knight; break;
199 case 'S': fromX = silver; break;
200 case 'G': fromX = gold; break;
201 case 'B': fromX = bishop; break;
202 case 'R': fromX = rook; break;
204 sprintf(line, "00%c%c%s", 'a'+'9'-toX, '1'+'9'-toY, astr_table_piece[(int)fromX]);
206 from = ('9' - fromY)*9 + (fromX - 'a');
207 Out("# from=%d\n",from);
208 sprintf(line, "%c%c%c%c%s", 'a'+'9'-fromX, '1'+'9'-fromY, 'a'+'9'-toX, '1'+'9'-toY,
209 astr_table_piece[abs(BOARD[from]) + (promo == '+' ? promote : 0)]);
214 IF("undo") { return 0; }
216 IF("ping") { Out("pong %d\n", value); }
221 static int CONV proce_cui( tree_t * restrict ptree )
226 token = strtok_r( str_cmdline, str_delimiters, &last );
228 if ( token == NULL || *token == '#' ) { return 1; }
232 if( proce_xboard(str_cmdline, token, ptree) ) return 1; // command already processed
233 Out("# translated command '%s'\n", str_cmdline); // command translated for processing by Bonanza
234 token = strtok_r( str_cmdline, str_delimiters, &last ); // redo parsing
236 if ( ! strcmp( token, "xboard" ) ) { xboard_mode = 1; game_status |= flag_noprompt; return 1; }
239 if ( ! strcmp( token, "analyze" ) ) { return cmd_analyze( ptree ); } // [HGM] analyze
240 if ( ! strcmp( token, "exit" ) ) { return cmd_exit(); } // [HGM] analyze
241 if ( ! strcmp( token, "move" ) ) { return cmd_move( ptree, &last ); }
242 if ( ! strcmp( token, "undo" ) ) { return cmd_undo( ptree ); } // [HGM] undo
243 analyze_mode = 0; // [HGM] analyze: all other commands terminate analysis
244 if ( is_move( token ) ) { return cmd_usrmove( ptree, token, &last ); }
245 if ( ! strcmp( token, "s" ) ) { return cmd_move_now(); }
246 if ( ! strcmp( token, "beep" ) ) { return cmd_beep( &last); }
247 if ( ! strcmp( token, "book" ) ) { return CmdBook( ptree, &last ); }
248 if ( ! strcmp( token, "display" ) ) { return cmd_display( ptree, &last ); }
249 if ( ! strcmp( token, "hash" ) ) { return cmd_hash( &last ); }
250 if ( ! strcmp( token, "limit" ) ) { return cmd_limit( &last ); }
251 if ( ! strcmp( token, "new" ) ) { return cmd_new( ptree, &last ); }
252 if ( ! strcmp( token, "outmove" ) ) { return cmd_outmove( ptree ); }
253 if ( ! strcmp( token, "peek" ) ) { return cmd_peek( &last ); }
254 if ( ! strcmp( token, "stdout" ) ) { return cmd_stdout( &last ); }
255 if ( ! strcmp( token, "ping" ) ) { return cmd_ping(); }
256 if ( ! strcmp( token, "ponder" ) ) { return cmd_ponder( &last ); }
257 if ( ! strcmp( token, "problem" ) ) { return cmd_problem( ptree, &last ); }
258 if ( ! strcmp( token, "quit" ) ) { return cmd_quit(); }
259 if ( ! strcmp( token, "read" ) ) { return cmd_read( ptree, &last ); }
260 if ( ! strcmp( token, "resign" ) ) { return cmd_resign( ptree, &last ); }
261 if ( ! strcmp( token, "suspend" ) ) { return cmd_suspend(); }
262 if ( ! strcmp( token, "time" ) ) { return cmd_time( &last ); }
263 if ( ! strcmp( token, "newlog" ) ) { return cmd_newlog( &last ); }
265 if ( ! strcmp( token, "connect" ) ) { return cmd_connect( ptree, &last ); }
266 if ( ! strcmp( token, "sendpv" ) ) { return cmd_sendpv( &last ); }
269 if ( ! strcmp( token, "mnj" ) ) { return cmd_mnj( &last ); }
272 if ( ! strcmp( token, "mpv" ) ) { return cmd_mpv( &last ); }
275 if ( ! strcmp( token, "dfpn" ) ) { return cmd_dfpn( ptree, &last ); }
277 #if defined(DFPN_CLIENT)
278 if ( ! strcmp( token, "dfpn_client")) { return cmd_dfpn_client( ptree,
282 if ( ! strcmp( token, "tlp" ) ) { return cmd_thread( &last ); }
284 #if ! defined(NO_STDOUT)
285 if ( ! strcmp( token, "stress" ) ) { return cmd_stress( &last ); }
287 #if ! defined(MINIMUM)
288 if ( ! strcmp( token, "learn" ) ) { return cmd_learn( ptree, &last ); }
291 str_error = str_bad_cmdline;
297 static int CONV proce_csalan( tree_t * restrict ptree )
302 token = strtok_r( str_cmdline, str_delimiters, &last );
304 if ( token == NULL ) { return 1; }
305 if ( *token == ach_turn[client_turn] && is_move( token+1 ) )
310 token = strtok_r( NULL, str_delimiters, &last );
311 if ( token == NULL || *token != 'T' )
313 str_error = str_bad_cmdline;
317 l = strtol( token+1, &ptr, 0 );
318 if ( token+1 == ptr || l == LONG_MAX || l < 1 )
320 str_error = str_bad_cmdline;
324 adjust_time( (unsigned int)l, client_turn );
325 Out( " elapsed: b%u, w%u\n", sec_b_total, sec_w_total );
328 if ( *token == ach_turn[Flip(client_turn)] && is_move( token+1 ) )
330 return cmd_usrmove( ptree, token+1, &last );
332 if ( ! strcmp( token, str_resign ) ) { return cmd_resign( ptree, &last ); }
333 if ( ! strcmp( token, "#WIN" )
334 || ! strcmp( token, "#LOSE" )
335 || ! strcmp( token, "#DRAW" )
336 || ! strcmp( token, "#CHUDAN" ) )
338 if ( game_status & ( flag_thinking | flag_pondering | flag_puzzling ) )
340 game_status |= flag_suspend;
344 if ( sckt_out( sckt_csa, "LOGOUT\n" ) < 0 ) { return -1; }
345 if ( sckt_recv_all( sckt_csa ) < 0 ) { return -1; }
349 if ( client_ngame == client_max_game ) { return cmd_quit(); }
351 return client_next_game( ptree, client_str_addr, (int)client_port );
360 static int CONV proce_mnj( tree_t * restrict ptree )
366 token = strtok_r( str_cmdline, str_delimiters, &last );
367 if ( token == NULL ) { return 1; }
369 if ( ! strcmp( token, "new" ) )
371 iret = cmd_suspend();
372 if ( iret != 1 ) { return iret; }
375 iret = cmd_new( ptree, &last );
376 if ( iret < 0 ) { return iret; }
378 moves_ignore[0] = MOVE_NA;
379 return analyze( ptree );
381 if ( ! strcmp( token, "ignore" ) ) { return cmd_mnjignore( ptree, &last ); }
382 if ( ! strcmp( token, "idle" ) ) { return cmd_suspend(); }
383 if ( ! strcmp( token, "alter" ) ) { return cmd_mnjmove( ptree, &last, 1 ); }
384 if ( ! strcmp( token, "retract" ) )
388 const char *str = strtok_r( NULL, str_delimiters, &last );
391 str_error = str_bad_cmdline;
394 l = strtol( str, &ptr, 0 );
395 if ( ptr == str || (long)NUM_UNMAKE < l )
397 str_error = str_bad_cmdline;
401 return cmd_mnjmove( ptree, &last, (int)l );
403 if ( ! strcmp( token, "move" ) ) { return cmd_mnjmove( ptree, &last, 0 ); }
405 str_error = str_bad_cmdline;
411 cmd_mnjignore( tree_t *restrict ptree, char **lasts )
420 token = strtok_r( NULL, str_delimiters, lasts );
423 str_error = str_bad_cmdline;
426 lid = strtol( token, &ptr, 0 );
427 if ( ptr == token || lid == LONG_MAX || lid < 1 )
429 str_error = str_bad_cmdline;
433 AbortDifficultCommand;
435 for ( i = 0; ; i += 1 )
437 token = strtok_r( NULL, str_delimiters, lasts );
438 if ( token == NULL ) { break; }
440 if ( interpret_CSA_move( ptree, &move, token ) < 0 ) { return -1; }
442 moves_ignore[i] = move;
446 str_error = str_bad_cmdline;
449 mnj_posi_id = (int)lid;
450 moves_ignore[i] = MOVE_NA;
452 return analyze( ptree );
457 cmd_mnjmove( tree_t * restrict ptree, char **lasts, int num_alter )
459 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
460 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
466 if ( sckt_mnj == SCKT_NULL || str1 == NULL || str2 == NULL )
468 str_error = str_bad_cmdline;
472 lid = strtol( str2, &ptr, 0 );
473 if ( ptr == str2 || lid == LONG_MAX || lid < 1 )
475 str_error = str_bad_cmdline;
479 AbortDifficultCommand;
483 iret = unmake_move_root( ptree );
484 if ( iret < 0 ) { return iret; }
489 iret = interpret_CSA_move( ptree, &move, str1 );
490 if ( iret < 0 ) { return iret; }
492 iret = get_elapsed( &time_turn_start );
493 if ( iret < 0 ) { return iret; }
495 mnj_posi_id = (int)lid;
497 iret = make_move_root( ptree, move, ( flag_time | flag_rep
498 | flag_detect_hang ) );
499 if ( iret < 0 ) { return iret; }
501 # if ! defined(NO_STDOUT)
502 iret = out_board( ptree, stdout, 0, 0 );
503 if ( iret < 0 ) { return iret; }
506 moves_ignore[0] = MOVE_NA;
507 return analyze( ptree );
513 do_analyze( tree_t * restrict ptree )
514 { // [HGM] analyze: do a ponder search on the current position
516 if ( get_elapsed( &time_start ) < 0 ) { return -1; }
517 time_limit = time_max_limit = 1e9; // kludge: use huge time to mimic infinity
519 if(xboard_mode) Out("1 0 0 0 New Search\n"); // make sure lower depth is emitted, so XBoard undestand new search started
521 game_status |= flag_pondering;
522 iret = iterate( ptree );
523 game_status &= ~flag_pondering;
529 cmd_undo( tree_t * restrict ptree )
530 { // [HGM] undo: restart the game, and feed all moves except the last
531 int i, last = move_ptr;
532 char *p = start_data;
533 if( move_ptr <= 0 ) {
534 str_error = "undo past start of game ignored";
538 AbortDifficultCommand;
541 cmd_new( ptree, &p );
542 for(i=0; i<last; i++) {
543 make_move_root( ptree, move_list[i], 0);
546 if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue after undo
553 cmd_analyze( tree_t * restrict ptree )
554 { // [HGM] analyze: switch on analyze mode, and start analyzing
555 AbortDifficultCommand;
558 return do_analyze( ptree );
564 { // [HGM] analyze: switch off analysis mode
565 if ( !analyze_mode ) {
566 str_error = "was not analyzing";
570 if ( game_status & flag_pondering ) { game_status |= flag_quit_ponder; return 2; }
578 static int CONV proce_usi( tree_t * restrict ptree )
584 token = strtok_r( str_cmdline, str_delimiters, &lasts );
585 if ( token == NULL ) { return 1; }
587 if ( ! strcmp( token, "usi" ) )
589 USIOut( "id name %s\n", str_myname );
590 USIOut( "id author Kunihito Hoki\n" );
595 if ( ! strcmp( token, "isready" ) )
597 USIOut( "readyok\n", str_myname );
601 if ( ! strcmp( token, "echo" ) )
603 USIOut( "%s\n", lasts );
607 if ( ! strcmp( token, "ignore_moves" ) )
609 return usi_ignore( ptree, &lasts );
612 if ( ! strcmp( token, "genmove_probability" ) )
614 if ( get_elapsed( &time_start ) < 0 ) { return -1; }
615 return usi_root_list( ptree );
618 if ( ! strcmp( token, "go" ) )
620 iret = usi_go( ptree, &lasts );
621 moves_ignore[0] = MOVE_NA;
625 if ( ! strcmp( token, "stop" ) ) { return cmd_move_now(); }
626 if ( ! strcmp( token, "position" ) ) { return usi_posi( ptree, &lasts ); }
627 if ( ! strcmp( token, "quit" ) ) { return cmd_quit(); }
629 str_error = str_bad_cmdline;
635 usi_ignore( tree_t * restrict ptree, char **lasts )
642 AbortDifficultCommand;
644 for ( i = 0; ; i += 1 )
646 token = strtok_r( NULL, str_delimiters, lasts );
647 if ( token == NULL ) { break; }
649 if ( usi2csa( ptree, token, str_buf ) < 0 ) { return -1; }
650 if ( interpret_CSA_move( ptree, &move, str_buf ) < 0 ) { return -1; }
652 moves_ignore[i] = move;
655 moves_ignore[i] = MOVE_NA;
662 usi_go( tree_t * restrict ptree, char **lasts )
669 AbortDifficultCommand;
671 if ( game_status & mask_game_end )
673 str_error = str_game_ended;
677 token = strtok_r( NULL, str_delimiters, lasts );
679 if ( ! strcmp( token, "book" ) )
681 AbortDifficultCommand;
682 if ( usi_book( ptree ) < 0 ) { return -1; }
688 if ( ! strcmp( token, "infinite" ) )
690 usi_byoyomi = UINT_MAX;
691 depth_limit = PLY_MAX;
692 node_limit = UINT64_MAX;
693 sec_limit_depth = UINT_MAX;
695 else if ( ! strcmp( token, "byoyomi" ) )
697 token = strtok_r( NULL, str_delimiters, lasts );
700 str_error = str_bad_cmdline;
704 l = strtol( token, &ptr, 0 );
705 if ( ptr == token || l > UINT_MAX || l < 1 )
707 str_error = str_bad_cmdline;
711 usi_byoyomi = (unsigned int)l;
712 depth_limit = PLY_MAX;
713 node_limit = UINT64_MAX;
714 sec_limit_depth = UINT_MAX;
717 str_error = str_bad_cmdline;
722 if ( get_elapsed( &time_turn_start ) < 0 ) { return -1; }
724 iret = com_turn_start( ptree, 0 );
726 if ( str_error == str_no_legal_move ) { USIOut( "bestmove resign\n" ); }
735 usi_posi( tree_t * restrict ptree, char **lasts )
741 AbortDifficultCommand;
743 moves_ignore[0] = MOVE_NA;
745 token = strtok_r( NULL, str_delimiters, lasts );
746 if ( strcmp( token, "startpos" ) )
748 str_error = str_bad_cmdline;
752 if ( ini_game( ptree, &min_posi_no_handicap,
753 flag_history, NULL, NULL ) < 0 ) { return -1; }
755 token = strtok_r( NULL, str_delimiters, lasts );
756 if ( token == NULL ) { return 1; }
758 if ( strcmp( token, "moves" ) )
760 str_error = str_bad_cmdline;
766 token = strtok_r( NULL, str_delimiters, lasts );
767 if ( token == NULL ) { break; }
769 if ( usi2csa( ptree, token, str_buf ) < 0 ) { return -1; }
770 if ( interpret_CSA_move( ptree, &move, str_buf ) < 0 ) { return -1; }
771 if ( make_move_root( ptree, move, ( flag_history | flag_time
773 | flag_detect_hang ) ) < 0 )
779 if ( get_elapsed( &time_turn_start ) < 0 ) { return -1; }
786 static int CONV cmd_move_now( void )
788 if ( game_status & flag_thinking ) { game_status |= flag_move_now; }
795 cmd_usrmove( tree_t * restrict ptree, const char *str_move, char **lasts )
803 if ( game_status & mask_game_end )
805 str_error = str_game_ended;
809 if ( game_status & flag_thinking )
811 str_error = str_busy_think;
815 str = strtok_r( NULL, str_delimiters, lasts );
816 if ( str == NULL ) { lelapsed = 0; }
820 str_error = str_bad_cmdline;
824 lelapsed = strtol( str, &ptr, 0 );
825 if ( ptr == str || lelapsed == LONG_MAX || lelapsed < 1 )
827 str_error = str_bad_cmdline;
832 if ( game_status & ( flag_pondering | flag_puzzling ) )
836 for ( i = 0; i < ponder_nmove; i++ )
838 if ( ! strcmp( str_move, str_CSA_move(ponder_move_list[i]) ) )
843 if ( i == ponder_nmove )
846 if ( sckt_csa != SCKT_NULL ) { AbortDifficultCommand; }
849 #if defined(CSASHOGI)
850 AbortDifficultCommand;
852 str_error = str_illegal_move;
857 if ( ( game_status & flag_puzzling )
858 || strcmp( str_move, str_CSA_move(ponder_move) ) )
860 ponder_move = MOVE_PONDER_FAILED;
861 game_status |= flag_quit_ponder;
865 iret = update_time( Flip(root_turn) );
866 if ( iret < 0 ) { return iret; }
869 adjust_time( (unsigned int)lelapsed, Flip(root_turn) );
872 out_CSA( ptree, &record_game, ponder_move );
874 game_status &= ~flag_pondering;
875 game_status |= flag_thinking;
879 set_search_limit_time( root_turn );
881 OutCsaShogi( "info ponder end\n" );
883 str = str_time_symple( time_turn_start - time_start );
884 Out( " %6s MOVE PREDICTION HIT\n"
885 " elapsed: b%u, w%u\n", str, sec_b_total, sec_w_total );
890 iret = interpret_CSA_move( ptree, &move, str_move );
891 if ( iret < 0 ) { return iret; }
892 move_evasion_pchk = 0;
893 iret = make_move_root( ptree, move, ( flag_rep | flag_history | flag_time
894 | flag_detect_hang ) );
899 if ( sckt_csa != SCKT_NULL )
901 if ( move_evasion_pchk )
903 str = str_CSA_move( move_evasion_pchk );
904 iret = sckt_out( sckt_csa, "%c%s\n",
905 ach_turn[Flip(root_turn)], str );
906 if ( iret < 0 ) { return iret; }
908 return cmd_suspend();
912 if ( move_evasion_pchk )
914 str = str_CSA_move( move_evasion_pchk );
915 #if defined(CSASHOGI)
916 OutCsaShogi( "move%s\n", str );
917 return cmd_suspend();
919 snprintf( str_message, SIZE_MESSAGE, "perpetual check (%c%s)",
920 ach_turn[Flip(root_turn)], str );
921 str_error = str_message;
929 if ( lelapsed ) { adjust_time( (unsigned int)lelapsed, Flip(root_turn) ); }
930 Out( " elapsed: b%u, w%u\n", sec_b_total, sec_w_total );
933 if ( sckt_csa != SCKT_NULL && ( game_status & flag_mated ) )
935 iret = sckt_out( sckt_csa, "%%TORYO\n" );
936 if ( iret < 0 ) { return iret; }
940 if ( ! ( game_status & mask_game_end ) )
942 iret = com_turn_start( ptree, 0 );
943 if ( iret < 0 ) { return iret; }
950 static int CONV cmd_beep( char **lasts )
952 const char *str = strtok_r( NULL, str_delimiters, lasts );
955 str_error = str_bad_cmdline;
959 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nobeep; }
960 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nobeep; }
962 str_error = str_bad_cmdline;
970 static int CONV cmd_peek( char **lasts )
972 const char *str = strtok_r( NULL, str_delimiters, lasts );
976 str_error = str_bad_cmdline;
980 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nopeek; }
981 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nopeek; }
983 str_error = str_bad_cmdline;
991 static int CONV cmd_stdout( char **lasts )
993 const char *str = strtok_r( NULL, str_delimiters, lasts );
997 str_error = str_bad_cmdline;
1001 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nostdout; }
1002 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nostdout; }
1004 str_error = str_bad_cmdline;
1012 static int CONV cmd_newlog( char **lasts )
1014 const char *str = strtok_r( NULL, str_delimiters, lasts );
1018 str_error = str_bad_cmdline;
1022 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nonewlog; }
1023 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nonewlog; }
1025 str_error = str_bad_cmdline;
1033 static int CONV cmd_ponder( char **lasts )
1035 const char *str = strtok_r( NULL, str_delimiters, lasts );
1039 str_error = str_bad_cmdline;
1043 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_noponder; }
1044 else if ( ! strcmp( str, str_off ) )
1046 if ( game_status & ( flag_pondering | flag_puzzling ) )
1048 game_status |= flag_quit_ponder;
1050 game_status |= flag_noponder;
1053 str_error = str_bad_cmdline;
1061 #if ! defined(NO_STDOUT)
1062 static int CONV cmd_stress( char **lasts )
1064 const char *str = strtok_r( NULL, str_delimiters, lasts );
1068 str_error = str_bad_cmdline;
1072 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nostress; }
1073 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nostress; }
1075 str_error = str_bad_cmdline;
1085 #if defined(MINIMUM)
1086 cmd_book( char **lasts )
1088 cmd_book( tree_t * restrict ptree, char **lasts )
1091 const char *str = strtok_r( NULL, str_delimiters, lasts );
1096 str_error = str_bad_cmdline;
1099 if ( ! strcmp( str, str_on ) ) { iret = book_on(); }
1100 else if ( ! strcmp( str, str_off ) ) { iret = book_off(); }
1101 else if ( ! strcmp( str, "narrow" ) ) { game_status |= flag_narrow_book; }
1102 else if ( ! strcmp( str, "wide" ) ) { game_status &= ~flag_narrow_book; }
1103 #if ! defined(MINIMUM)
1104 else if ( ! strcmp( str, "create" ) )
1106 AbortDifficultCommand;
1108 iret = book_create( ptree );
1109 if ( iret < 0 ) { return iret; }
1111 iret = ini_game( ptree, &min_posi_no_handicap, flag_history,
1113 if ( iret < 0 ) { return iret; }
1115 iret = get_elapsed( &time_turn_start );
1119 str_error = str_bad_cmdline;
1127 static int CONV cmd_display( tree_t * restrict ptree, char **lasts )
1129 const char *str = strtok_r( NULL, str_delimiters, lasts );
1136 l = strtol( str, &ptr, 0 );
1139 str_error = str_bad_cmdline;
1142 if ( l == 1 ) { game_status &= ~flag_reverse; }
1143 else if ( l == 2 ) { game_status |= flag_reverse; }
1145 str_error = str_bad_cmdline;
1151 iret = out_board( ptree, stdout, 0, 0 );
1152 if ( iret < 0 ) { return iret; }
1153 #if ! defined(NO_LOGGING)
1154 iret = out_board( ptree, pf_log, 0, 0 );
1155 if ( iret < 0 ) { return iret; }
1163 static int CONV cmd_ping( void )
1165 OutCsaShogi( "pong\n" );
1171 static int CONV cmd_hash( char **lasts )
1173 const char *str = strtok_r( NULL, str_delimiters, lasts );
1179 str_error = str_bad_cmdline;
1183 l = strtol( str, &ptr, 0 );
1184 if ( ptr == str || l == LONG_MAX || l < 1 || l > 31 )
1186 str_error = str_bad_cmdline;
1190 AbortDifficultCommand;
1192 log2_ntrans_table = (int)l;
1193 memory_free( (void *)ptrans_table_orig );
1194 return ini_trans_table();
1198 static int CONV cmd_limit( char **lasts )
1200 const char *str = strtok_r( NULL, str_delimiters, lasts );
1206 str_error = str_bad_cmdline;
1210 AbortDifficultCommand;
1212 if ( ! strcmp( str, "depth" ) )
1214 str = strtok_r( NULL, str_delimiters, lasts );
1217 str_error = str_bad_cmdline;
1220 l1 = strtol( str, &ptr, 0 );
1221 if ( ptr == str || l1 == LONG_MAX || l1 < 1 )
1223 str_error = str_bad_cmdline;
1226 sec_limit_up = UINT_MAX;
1227 node_limit = UINT64_MAX;
1228 depth_limit = (int)l1;
1230 else if ( ! strcmp( str, "nodes" ) )
1232 str = strtok_r( NULL, str_delimiters, lasts );
1235 str_error = str_bad_cmdline;
1238 l1 = strtol( str, &ptr, 0 );
1239 if ( ptr == str || l1 == LONG_MAX || l1 < 1 )
1241 str_error = str_bad_cmdline;
1244 sec_limit_up = UINT_MAX;
1245 depth_limit = PLY_MAX;
1246 node_limit = (uint64_t)l1;
1248 else if ( ! strcmp( str, "time" ) )
1250 str = strtok_r( NULL, str_delimiters, lasts );
1253 str_error = str_bad_cmdline;
1257 if ( ! strcmp( str, "extendable" ) )
1259 game_status |= flag_time_extendable;
1261 else if ( ! strcmp( str, "strict" ) )
1263 game_status &= ~flag_time_extendable;
1266 l1 = strtol( str, &ptr, 0 );
1267 if ( ptr == str || l1 == LONG_MAX || l1 < 0 )
1269 str_error = str_bad_cmdline;
1273 str = strtok_r( NULL, str_delimiters, lasts );
1276 str_error = str_bad_cmdline;
1279 l2 = strtol( str, &ptr, 0 );
1280 if ( ptr == str || l2 == LONG_MAX || l2 < 0 )
1282 str_error = str_bad_cmdline;
1286 str = strtok_r( NULL, str_delimiters, lasts );
1287 if ( ! str ) { l3 = -1; }
1289 l3 = strtol( str, &ptr, 0 );
1290 if ( ptr == str || l3 >= PLY_MAX || l3 < -1 )
1292 str_error = str_bad_cmdline;
1297 if ( ! ( l1 | l2 ) ) { l2 = 1; }
1299 depth_limit = PLY_MAX;
1300 node_limit = UINT64_MAX;
1301 sec_limit = (unsigned int)l1 * 60U;
1302 sec_limit_up = (unsigned int)l2;
1303 if ( l3 == -1 ) { sec_limit_depth = UINT_MAX; }
1304 else { sec_limit_depth = (unsigned int)l3; }
1308 str_error = str_bad_cmdline;
1317 cmd_read( tree_t * restrict ptree, char **lasts )
1319 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1320 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1321 const char *str3 = strtok_r( NULL, str_delimiters, lasts );
1322 const char *str_tmp;
1323 FILE *pf_src, *pf_dest;
1324 char str_file[SIZE_FILENAME];
1330 flag = flag_history | flag_rep | flag_detect_hang;
1336 str_error = str_bad_cmdline;
1342 if ( ! strcmp( str2, "t" ) ) { flag |= flag_time; }
1343 else if ( strcmp( str2, "nil" ) )
1345 str_error = str_bad_cmdline;
1352 l = strtol( str3, &ptr, 0 );
1353 if ( ptr == str3 || l == LONG_MAX || l < 1 )
1355 str_error = str_bad_cmdline;
1358 moves = (unsigned int)l - 1U;
1361 AbortDifficultCommand;
1363 if ( ! strcmp( str1, "." ) )
1365 str_tmp = "game.cs_";
1367 #if defined(NO_LOGGING)
1368 strncpy( str_file, "game.csa", SIZE_FILENAME-1 );
1370 snprintf( str_file, SIZE_FILENAME, "%s/game%03d.csa",
1371 str_dir_logs, record_num );
1373 pf_dest = file_open( str_tmp, "w" );
1374 if ( pf_dest == NULL ) { return -2; }
1376 pf_src = file_open( str_file, "r" );
1377 if ( pf_src == NULL )
1379 file_close( pf_dest );
1383 while ( ( c = getc(pf_src) ) != EOF ) { putc( c, pf_dest ); }
1385 iret = file_close( pf_src );
1388 file_close( pf_dest );
1392 iret = file_close( pf_dest );
1393 if ( iret < 0 ) { return iret; }
1399 iret = read_record( ptree, str1, moves, flag );
1400 if ( iret < 0 ) { return iret; }
1402 iret = get_elapsed( &time_turn_start );
1403 if ( iret < 0 ) { return iret; }
1405 if ( str_tmp && remove( str_tmp ) )
1407 out_warning( "remove() failed." );
1415 static int CONV cmd_resign( tree_t * restrict ptree, char **lasts )
1417 const char *str = strtok_r( NULL, str_delimiters, lasts );
1421 if ( str == NULL || *str == 'T' )
1423 AbortDifficultCommand;
1425 if ( game_status & mask_game_end ) { return 1; }
1427 game_status |= flag_resigned;
1428 update_time( root_turn );
1429 out_CSA( ptree, &record_game, MOVE_RESIGN );
1432 l = strtol( str, &ptr, 0 );
1433 if ( ptr == str || l == LONG_MAX || l < MT_CAP_PAWN )
1435 str_error = str_bad_cmdline;
1438 resign_threshold = (int)l;
1445 static int CONV cmd_move( tree_t * restrict ptree, char **lasts )
1447 const char *str = strtok_r( NULL, str_delimiters, lasts );
1453 if ( game_status & mask_game_end )
1455 str_error = str_game_ended;
1459 AbortDifficultCommand;
1463 if ( analyze_mode ) // [HGM] analyze: in analysis mode we cannot set the engine thinking (but perhaps play PV move?)
1465 str_error = str_bad_cmdline;
1469 iret = get_elapsed( &time_turn_start );
1470 if ( iret < 0 ) { return iret; }
1472 return com_turn_start( ptree, 0 );
1475 l = strtol( str, &ptr, 0 );
1476 if ( str != ptr && l != LONG_MAX && l >= 1 && *ptr == '\0' )
1478 if ( analyze_mode ) // [HGM] analyze: in analysis mode we cannot set the engine thinking
1480 str_error = str_bad_cmdline;
1484 for ( i = 0; i < l; i += 1 )
1486 if ( game_status & ( flag_move_now | mask_game_end ) ) { break; }
1488 iret = get_elapsed( &time_turn_start );
1489 if ( iret < 0 ) { return iret; }
1491 iret = com_turn_start( ptree, 0 );
1492 if ( iret < 0 ) { return iret; }
1499 iret = interpret_CSA_move( ptree, &move, str );
1500 if ( iret < 0 ) { return iret; }
1502 iret = get_elapsed( &time_turn_start );
1503 if ( iret < 0 ) { return iret; }
1505 iret = make_move_root( ptree, move,
1506 ( flag_history | flag_time | flag_rep
1507 | flag_detect_hang ) );
1508 if ( iret < 0 ) { return iret; }
1510 str = strtok_r( NULL, str_delimiters, lasts );
1512 } while ( str != NULL );
1514 if ( analyze_mode ) return do_analyze ( ptree ); // [HGM] analyze: analysis should continue after feeding moves
1520 static int CONV cmd_new( tree_t * restrict ptree, char **lasts )
1522 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1523 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1524 const min_posi_t *pmp;
1525 min_posi_t min_posi;
1528 AbortDifficultCommand;
1530 start_pos = *lasts; move_ptr = 0; // [HGM] undo: remember start position
1534 strncpy(start_data, str1, 511); // [HGM] undo: remember start position
1535 memset( &min_posi.asquare, empty, nsquare );
1536 min_posi.hand_black = min_posi.hand_white = 0;
1537 iret = read_board_rep1( str1, &min_posi );
1538 if ( iret < 0 ) { return iret; }
1542 if ( ! strcmp( str2, "-" ) ) { min_posi.turn_to_move = white; }
1543 else if ( ! strcmp( str2, "+" ) ) { min_posi.turn_to_move = black; }
1545 str_error = str_bad_cmdline;
1549 else { min_posi.turn_to_move = black; }
1553 else { pmp = &min_posi_no_handicap; }
1555 iret = ini_game( ptree, pmp, flag_history, NULL, NULL );
1556 if ( iret < 0 ) { return iret; }
1558 return get_elapsed( &time_turn_start );
1562 static int CONV cmd_outmove( tree_t * restrict ptree )
1564 const char *str_move;
1566 unsigned int move_list[ MAX_LEGAL_MOVES ];
1569 AbortDifficultCommand;
1571 if ( game_status & mask_game_end )
1573 Out( "NO LEGAL MOVE\n" );
1574 DFPNOut( "NO LEGAL MOVE\n" );
1578 n = gen_legal_moves( ptree, move_list, 0 );
1581 for ( c = i = 0; i < n; i += 1 )
1583 str_move = str_CSA_move(move_list[i]);
1585 if ( i && ( i % 10 ) == 0 )
1587 Out( "%s\n", buffer );
1588 DFPNOut( "%s ", buffer );
1589 memcpy( buffer, str_move, 6 );
1595 memcpy( buffer + c + 1, str_move, 6 );
1599 memcpy( buffer + c, str_move, 6 );
1604 Out( "%s\n", buffer );
1605 DFPNOut( "%s\n", buffer );
1611 static int CONV cmd_problem( tree_t * restrict ptree, char **lasts )
1613 const char *str = strtok_r( NULL, str_delimiters, lasts );
1616 unsigned int nposition;
1622 AbortDifficultCommand;
1627 if ( str != NULL && ! strcmp( str, "mate" ) )
1630 str = strtok_r( NULL, str_delimiters, lasts );
1636 l = strtol( str, &ptr, 0 );
1637 if ( ptr == str || l == LONG_MAX || l < 1 )
1639 str_error = str_bad_cmdline;
1642 nposition = (unsigned int)l;
1644 else { nposition = UINT_MAX; }
1647 iret = record_open( &record_problems, "problem.csa", mode_read, NULL, NULL );
1648 if ( iret < 0 ) { return iret; }
1651 iret = is_mate ? solve_mate_problems( ptree, nposition )
1652 : solve_problems( ptree, nposition );
1654 iret = solve_problems( ptree, nposition );
1659 record_close( &record_problems );
1663 iret = record_close( &record_problems );
1664 if ( iret < 0 ) { return iret; }
1666 return get_elapsed( &time_turn_start );
1670 static int CONV cmd_quit( void )
1672 game_status |= flag_quit;
1677 static int CONV cmd_suspend( void )
1679 if ( game_status & ( flag_pondering | flag_puzzling ) )
1681 game_status |= flag_quit_ponder;
1685 game_status |= flag_suspend;
1690 static int CONV cmd_time( char **lasts )
1692 const char *str = strtok_r( NULL, str_delimiters, lasts );
1697 str_error = str_bad_cmdline;
1700 else if ( ! strcmp( str, "response" ) )
1703 str = strtok_r( NULL, str_delimiters, lasts );
1706 str_error = str_bad_cmdline;
1709 l = strtol( str, &ptr, 0 );
1710 if ( ptr == str || l == LONG_MAX || l < 0 || l > 1000 )
1712 str_error = str_bad_cmdline;
1715 time_response = (unsigned int)l;
1718 else if ( ! strcmp( str, "remain" ) )
1722 str = strtok_r( NULL, str_delimiters, lasts );
1725 str_error = str_bad_cmdline;
1728 l1 = strtol( str, &ptr, 0 );
1729 if ( ptr == str || l1 == LONG_MAX || l1 < 0 )
1731 str_error = str_bad_cmdline;
1735 str = strtok_r( NULL, str_delimiters, lasts );
1738 str_error = str_bad_cmdline;
1741 l2 = strtol( str, &ptr, 0 );
1742 if ( ptr == str || l2 == LONG_MAX || l2 < 0 )
1744 str_error = str_bad_cmdline;
1748 if ( sec_limit_up == UINT_MAX )
1750 str_error = str_bad_cmdline;
1754 return reset_time( (unsigned int)l1, (unsigned int)l2 );
1757 str_error = str_bad_cmdline;
1762 #if !defined(MINIMUM)
1763 /* learn (ini|no-ini) steps games iterations tlp1 tlp2 */
1764 static int CONV cmd_learn( tree_t * restrict ptree, char **lasts )
1766 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1767 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1768 const char *str3 = strtok_r( NULL, str_delimiters, lasts );
1769 const char *str4 = strtok_r( NULL, str_delimiters, lasts );
1771 const char *str5 = strtok_r( NULL, str_delimiters, lasts );
1772 const char *str6 = strtok_r( NULL, str_delimiters, lasts );
1776 unsigned int max_games;
1777 int is_ini, nsteps, max_iterations, nworker1, nworker2, iret;
1781 str_error = str_bad_cmdline;
1784 if ( ! strcmp( str1, "ini" ) ) { is_ini = 1; }
1785 else if ( ! strcmp( str1, "no-ini" ) ) { is_ini = 0; }
1787 str_error = str_bad_cmdline;
1791 max_games = UINT_MAX;
1792 max_iterations = INT_MAX;
1793 nworker1 = nworker2 = nsteps = 1;
1797 l = strtol( str2, &ptr, 0 );
1798 if ( ptr == str2 || l == LONG_MAX || l < 1 )
1800 str_error = str_bad_cmdline;
1808 l = strtol( str3, &ptr, 0 );
1809 if ( ptr == str3 || l == LONG_MAX || l == LONG_MIN )
1811 str_error = str_bad_cmdline;
1814 if ( l > 0 ) { max_games = (unsigned int)l; }
1819 l = strtol( str4, &ptr, 0 );
1820 if ( ptr == str4 || l == LONG_MAX || l == LONG_MIN )
1822 str_error = str_bad_cmdline;
1825 if ( l > 0 ) { max_iterations = (int)l; }
1831 l = strtol( str5, &ptr, 0 );
1832 if ( ptr == str5 || l > TLP_MAX_THREADS || l < 1 )
1834 str_error = str_bad_cmdline;
1842 l = strtol( str6, &ptr, 0 );
1843 if ( ptr == str6 || l > TLP_MAX_THREADS || l < 1 )
1845 str_error = str_bad_cmdline;
1852 AbortDifficultCommand;
1854 log2_ntrans_table = 12;
1856 memory_free( (void *)ptrans_table_orig );
1858 iret = ini_trans_table();
1859 if ( iret < 0 ) { return iret; }
1861 iret = learn( ptree, is_ini, nsteps, max_games, max_iterations,
1862 nworker1, nworker2 );
1863 if ( iret < 0 ) { return -1; }
1865 iret = ini_game( ptree, &min_posi_no_handicap, flag_history, NULL, NULL );
1866 if ( iret < 0 ) { return -1; }
1868 iret = get_elapsed( &time_turn_start );
1869 if ( iret < 0 ) { return iret; }
1873 #endif /* MINIMUM */
1877 static int CONV cmd_mpv( char **lasts )
1879 const char *str = strtok_r( NULL, str_delimiters, lasts );
1885 str_error = str_bad_cmdline;
1888 else if ( ! strcmp( str, "num" ) )
1890 str = strtok_r( NULL, str_delimiters, lasts );
1893 str_error = str_bad_cmdline;
1896 l = strtol( str, &ptr, 0 );
1897 if ( ptr == str || l == LONG_MAX || l < 1 || l > MPV_MAX_PV )
1899 str_error = str_bad_cmdline;
1903 AbortDifficultCommand;
1909 else if ( ! strcmp( str, "width" ) )
1911 str = strtok_r( NULL, str_delimiters, lasts );
1914 str_error = str_bad_cmdline;
1917 l = strtol( str, &ptr, 0 );
1918 if ( ptr == str || l == LONG_MAX || l < MT_CAP_PAWN )
1920 str_error = str_bad_cmdline;
1924 AbortDifficultCommand;
1931 str_error = str_bad_cmdline;
1938 static int CONV cmd_dfpn( tree_t * restrict ptree, char **lasts )
1940 const char *str = strtok_r( NULL, str_delimiters, lasts );
1944 str_error = str_bad_cmdline;
1947 else if ( ! strcmp( str, "hash" ) )
1952 str = strtok_r( NULL, str_delimiters, lasts );
1955 str_error = str_bad_cmdline;
1958 l = strtol( str, &ptr, 0 );
1959 if ( ptr == str || l == LONG_MAX || l < 1 )
1961 str_error = str_bad_cmdline;
1965 AbortDifficultCommand;
1967 dfpn_hash_log2 = (unsigned int)l;
1968 return dfpn_ini_hash();
1970 else if ( ! strcmp( str, "go" ) )
1972 AbortDifficultCommand;
1974 return dfpn( ptree, root_turn, 1 );
1976 else if ( ! strcmp( str, "connect" ) )
1984 str = strtok_r( NULL, str_delimiters, lasts );
1985 if ( ! str || ! strcmp( str, "." ) ) { str = "127.0.0.1"; }
1986 strncpy( str_addr, str, 255 );
1987 str_addr[255] = '\0';
1989 str = strtok_r( NULL, str_delimiters, lasts );
1990 if ( ! str || ! strcmp( str, "." ) ) { str = "4083"; }
1991 l = strtol( str, &ptr, 0 );
1992 if ( ptr == str || l == LONG_MAX || l < 0 || l > USHRT_MAX )
1994 str_error = str_bad_cmdline;
1999 str = strtok_r( NULL, str_delimiters, lasts );
2000 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza1"; }
2001 strncpy( str_id, str, 255 );
2004 AbortDifficultCommand;
2006 dfpn_sckt = sckt_connect( str_addr, port );
2007 if ( dfpn_sckt == SCKT_NULL ) { return -2; }
2009 str_buffer_cmdline[0] = '\0';
2010 DFPNOut( "Worker: %s\n", str_id );
2015 str_error = str_bad_cmdline;
2022 static int CONV cmd_thread( char **lasts )
2024 const char *str = strtok_r( NULL, str_delimiters, lasts );
2028 str_error = str_bad_cmdline;
2031 else if ( ! strcmp( str, "num" ) )
2036 str = strtok_r( NULL, str_delimiters, lasts );
2039 str_error = str_bad_cmdline;
2042 l = strtol( str, &ptr, 0 );
2043 if ( ptr == str || l == LONG_MAX || l < 1 || l > TLP_MAX_THREADS )
2045 str_error = str_bad_cmdline;
2053 if ( game_status & ( flag_thinking | flag_pondering | flag_puzzling ) )
2060 str_error = str_bad_cmdline;
2066 #if defined(DFPN_CLIENT)
2067 static int CONV cmd_dfpn_client( tree_t * restrict ptree, char **lasts )
2073 AbortDifficultCommand;
2075 str = strtok_r( NULL, str_delimiters, lasts );
2076 if ( ! str || ! strcmp( str, "." ) ) { str = "127.0.0.1"; }
2077 strncpy( dfpn_client_str_addr, str, 255 );
2078 dfpn_client_str_addr[255] = '\0';
2080 str = strtok_r( NULL, str_delimiters, lasts );
2081 if ( ! str || ! strcmp( str, "." ) ) { str = "4083"; }
2082 dfpn_client_port = strtol( str, &ptr, 0 );
2083 if ( ptr == str || dfpn_client_port == LONG_MAX || dfpn_client_port < 0
2084 || dfpn_client_port > USHRT_MAX )
2086 str_error = str_bad_cmdline;
2090 Out( "DFPN Server: %s %d\n", dfpn_client_str_addr, dfpn_client_port );
2092 iret = ini_game( ptree, &min_posi_no_handicap, flag_history, NULL, NULL );
2093 if ( iret < 0 ) { return iret; }
2095 if ( dfpn_client_sckt == SCKT_NULL )
2097 str_error = "Check network status.";
2101 return get_elapsed( &time_turn_start );
2106 #if defined(CSA_LAN)
2107 static int CONV cmd_connect( tree_t * restrict ptree, char **lasts )
2113 str = strtok_r( NULL, str_delimiters, lasts );
2114 if ( ! str || ! strcmp( str, "." ) ) { str = "gserver.computer-shogi.org"; }
2115 strncpy( client_str_addr, str, 255 );
2116 client_str_addr[255] = '\0';
2118 str = strtok_r( NULL, str_delimiters, lasts );
2119 if ( ! str || ! strcmp( str, "." ) ) { str = "4081"; }
2120 client_port = strtol( str, &ptr, 0 );
2121 if ( ptr == str || client_port == LONG_MAX || client_port < 0
2122 || client_port > USHRT_MAX )
2124 str_error = str_bad_cmdline;
2128 str = strtok_r( NULL, str_delimiters, lasts );
2129 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza_test"; }
2130 strncpy( client_str_id, str, 255 );
2131 client_str_id[255] = '\0';
2133 str = strtok_r( NULL, " \t", lasts );
2134 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza_test"; }
2135 strncpy( client_str_pwd, str, 255 );
2136 client_str_pwd[255] = '\0';
2138 str = strtok_r( NULL, str_delimiters, lasts );
2139 if ( ! str || ! strcmp( str, "." ) ) { client_max_game = INT_MAX; }
2141 max_games = strtol( str, &ptr, 0 );
2142 if ( ptr == str || max_games == LONG_MAX || max_games < 1 )
2144 str_error = str_bad_cmdline;
2147 client_max_game = max_games;
2150 AbortDifficultCommand;
2154 return client_next_game( ptree, client_str_addr, (int)client_port );
2158 static int CONV cmd_sendpv( char **lasts )
2160 const char *str = strtok_r( NULL, str_delimiters, lasts );
2164 str_error = str_bad_cmdline;
2168 if ( ! strcmp( str, str_off ) ) { game_status &= ~flag_sendpv; }
2169 else if ( ! strcmp( str, str_on ) ) { game_status |= flag_sendpv; }
2171 str_error = str_bad_cmdline;
2180 #if defined(MNJ_LAN)
2181 /* mnj sd seed addr port name factor stable_depth */
2182 static int CONV cmd_mnj( char **lasts )
2184 char client_str_addr[256];
2185 char client_str_id[256];
2190 int client_port, sd;
2193 str = strtok_r( NULL, str_delimiters, lasts );
2196 str_error = str_bad_cmdline;
2199 l = strtol( str, &ptr, 0 );
2200 if ( ptr == str || l == LONG_MAX || l < 0 )
2202 str_error = str_bad_cmdline;
2208 str = strtok_r( NULL, str_delimiters, lasts );
2211 str_error = str_bad_cmdline;
2214 l = strtol( str, &ptr, 0 );
2215 if ( ptr == str || l == LONG_MAX || l < 0 )
2217 str_error = str_bad_cmdline;
2220 seed = (unsigned int)l;
2223 str = strtok_r( NULL, str_delimiters, lasts );
2224 if ( ! str || ! strcmp( str, "." ) ) { str = "localhost"; }
2225 strncpy( client_str_addr, str, 255 );
2226 client_str_addr[255] = '\0';
2229 str = strtok_r( NULL, str_delimiters, lasts );
2230 if ( ! str || ! strcmp( str, "." ) ) { str = "4082"; }
2231 l = strtol( str, &ptr, 0 );
2232 if ( ptr == str || l == LONG_MAX || l < 0 || l > USHRT_MAX )
2234 str_error = str_bad_cmdline;
2237 client_port = (int)l;
2240 str = strtok_r( NULL, str_delimiters, lasts );
2241 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza1"; }
2242 strncpy( client_str_id, str, 255 );
2243 client_str_id[255] = '\0';
2245 str = strtok_r( NULL, str_delimiters, lasts );
2246 if ( ! str || ! strcmp( str, "." ) ) { str = "1.0"; }
2247 factor = strtod( str, &ptr );
2248 if ( ptr == str || factor < 0.0 )
2250 str_error = str_bad_cmdline;
2254 str = strtok_r( NULL, str_delimiters, lasts );
2255 if ( ! str || ! strcmp( str, "." ) ) { l = -1; }
2257 l = strtol( str, &ptr, 0 );
2258 if ( ptr == str || l == LONG_MAX )
2260 str_error = str_bad_cmdline;
2264 if ( l <= 0 ) { mnj_depth_stable = INT_MAX; }
2265 else { mnj_depth_stable = (int)l; }
2267 AbortDifficultCommand;
2269 resign_threshold = 65535;
2270 game_status |= ( flag_noponder | flag_noprompt );
2271 if ( mnj_reset_tbl( sd, seed ) < 0 ) { return -1; }
2273 sckt_mnj = sckt_connect( client_str_addr, (int)client_port );
2274 if ( sckt_mnj == SCKT_NULL ) { return -2; }
2276 str_buffer_cmdline[0] = '\0';
2278 Out( "Sending my name %s", client_str_id );
2279 MnjOut( "%s %g final%s\n", client_str_id, factor,
2280 ( mnj_depth_stable == INT_MAX ) ? "" : " stable" );
2282 return cmd_suspend();