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_time( char **lasts );
96 int CONV is_move( const char *str )
98 if ( isdigit( (int)str[0] ) && isdigit( (int)str[1] )
99 && isdigit( (int)str[2] ) && isdigit( (int)str[3] )
100 && isupper( (int)str[4] ) && isupper( (int)str[5] )
101 && str[6] == '\0' ) { return 1; }
108 procedure( tree_t * restrict ptree )
111 if ( sckt_csa != SCKT_NULL ) { return proce_csalan( ptree ); }
115 if ( sckt_mnj != SCKT_NULL ) { return proce_mnj( ptree ); }
119 if ( usi_mode != usi_off ) { return proce_usi( ptree ); }
122 return proce_cui( ptree );
126 #define IF(X) else if(!strcmp(command, X))
128 int myTime, hisTime, movesPerSession, inc, plyNr;
133 { // set white and black times from own and opponent time.
135 if(movesPerSession <= 0) moves = 35; else {
137 while(moves <= 0) moves += movesPerSession;
139 time_limit = (myTime-inc-30)/(moves+2) + inc;
140 time_max_limit = 3*time_limit;
141 if(time_max_limit > myTime - 30)time_max_limit = myTime - 30; // keep 0.3 sec margin, as Bonanza reads the clock infrequently
142 time_limit *= 10; // msec
143 time_max_limit *= 10;
144 Out("# moves=%d, time=%d inc=%d t=%d, max=%d\n", moves, myTime, inc, time_limit, time_max_limit);
148 proce_xboard(char *line, const char *command, tree_t * restrict ptree)
149 { // [HGM] added to make Bonanza.exe a native WinBoard engine
151 static char forceMode = 0;
152 sscanf(line + strlen(command) + 1, "%d", &value);
153 Out("# command = '%s'\n", line);
155 IF("protover") { Out("feature variants=\"shogi\" usermove=1 myname=\"Bonanza " BNZ_VER
156 "\" memory=1 smp=1 debug=1 colors=0 setboard=1 ping=1 done=1\n"); }
157 IF("new") { forceMode = plyNr = 0; SetTimes(); return 0; }
158 IF("easy") { strcpy(line, "ponder off"); return 0; }
159 IF("hard") { strcpy(line, "ponder on"); return 0; }
162 IF("time") { sscanf(line+5, "%d", &myTime); }
163 IF("otim") { sscanf(line+5, "%d", &hisTime); }
164 IF("force") { forceMode = 1; }
165 IF("go") { forceMode = 0; SetTimes(); plyNr++; strcpy(line, "move"); return 0; }
167 IF("cores") { sprintf(line, "tlp num %d", value); return 0; }
168 IF("sd") { sprintf(line, "limit depth %d", value); return 0; }
170 IF("quit") { return 0; }
173 IF("variant") { /* ignore, since it must be Shogi */; }
176 IF("level") { int min, sec; float fsec=0.;
177 if(sscanf(line+6, "%d %d:%d %f", &movesPerSession, &min, &sec, &fsec) != 4)
178 sscanf(line+6, "%d %d %f", &movesPerSession, &min, &fsec);
179 min = 60*min + sec; myTime = hisTime = 100*min; inc = 100 * fsec;
181 IF("usermove") { char fromX=line[9], fromY=line[10], toX=line[11], toY=line[12], promo=line[13];
183 {int i,j;for(i=0;i<81;i+=9){printf("# ");for(j=0;j<9;j++)printf(" %3d", BOARD[i+j]);printf("\n");}}
184 if(forceMode) strcpy(line, "move "), line += 5; else plyNr++, SetTimes();
185 if(fromY == '@') { // drop
186 if(fromX >= 'a') fromX += 'A' - 'a';
187 switch(fromX) { // encode piece
188 case 'P': fromX = pawn; break;
189 case 'L': fromX = lance; break;
190 case 'N': fromX = knight; break;
191 case 'S': fromX = silver; break;
192 case 'G': fromX = gold; break;
193 case 'B': fromX = bishop; break;
194 case 'R': fromX = rook; break;
196 sprintf(line, "00%c%c%s", 'a'+'9'-toX, '1'+'9'-toY, astr_table_piece[(int)fromX]);
198 from = ('9' - fromY)*9 + (fromX - 'a');
199 Out("# from=%d\n",from);
200 sprintf(line, "%c%c%c%c%s", 'a'+'9'-fromX, '1'+'9'-fromY, 'a'+'9'-toX, '1'+'9'-toY,
201 astr_table_piece[abs(BOARD[from]) + (promo == '+' ? promote : 0)]);
207 IF("ping") { Out("pong %d\n", value); }
212 static int CONV proce_cui( tree_t * restrict ptree )
217 token = strtok_r( str_cmdline, str_delimiters, &last );
219 if ( token == NULL || *token == '#' ) { return 1; }
223 if( proce_xboard(str_cmdline, token, ptree) ) return 1; // command already processed
224 Out("# translated command '%s'\n", str_cmdline); // command translated for processing by Bonanza
225 token = strtok_r( str_cmdline, str_delimiters, &last ); // redo parsing
227 if ( ! strcmp( token, "xboard" ) ) { xboard_mode = 1; game_status |= flag_noprompt; return 1; }
230 if ( is_move( token ) ) { return cmd_usrmove( ptree, token, &last ); }
231 if ( ! strcmp( token, "s" ) ) { return cmd_move_now(); }
232 if ( ! strcmp( token, "beep" ) ) { return cmd_beep( &last); }
233 if ( ! strcmp( token, "book" ) ) { return CmdBook( ptree, &last ); }
234 if ( ! strcmp( token, "display" ) ) { return cmd_display( ptree, &last ); }
235 if ( ! strcmp( token, "hash" ) ) { return cmd_hash( &last ); }
236 if ( ! strcmp( token, "limit" ) ) { return cmd_limit( &last ); }
237 if ( ! strcmp( token, "move" ) ) { return cmd_move( ptree, &last ); }
238 if ( ! strcmp( token, "new" ) ) { return cmd_new( ptree, &last ); }
239 if ( ! strcmp( token, "outmove" ) ) { return cmd_outmove( ptree ); }
240 if ( ! strcmp( token, "peek" ) ) { return cmd_peek( &last ); }
241 if ( ! strcmp( token, "stdout" ) ) { return cmd_stdout( &last ); }
242 if ( ! strcmp( token, "ping" ) ) { return cmd_ping(); }
243 if ( ! strcmp( token, "ponder" ) ) { return cmd_ponder( &last ); }
244 if ( ! strcmp( token, "problem" ) ) { return cmd_problem( ptree, &last ); }
245 if ( ! strcmp( token, "quit" ) ) { return cmd_quit(); }
246 if ( ! strcmp( token, "read" ) ) { return cmd_read( ptree, &last ); }
247 if ( ! strcmp( token, "resign" ) ) { return cmd_resign( ptree, &last ); }
248 if ( ! strcmp( token, "suspend" ) ) { return cmd_suspend(); }
249 if ( ! strcmp( token, "time" ) ) { return cmd_time( &last ); }
250 if ( ! strcmp( token, "newlog" ) ) { return cmd_newlog( &last ); }
252 if ( ! strcmp( token, "connect" ) ) { return cmd_connect( ptree, &last ); }
253 if ( ! strcmp( token, "sendpv" ) ) { return cmd_sendpv( &last ); }
256 if ( ! strcmp( token, "mnj" ) ) { return cmd_mnj( &last ); }
259 if ( ! strcmp( token, "mpv" ) ) { return cmd_mpv( &last ); }
262 if ( ! strcmp( token, "dfpn" ) ) { return cmd_dfpn( ptree, &last ); }
264 #if defined(DFPN_CLIENT)
265 if ( ! strcmp( token, "dfpn_client")) { return cmd_dfpn_client( ptree,
269 if ( ! strcmp( token, "tlp" ) ) { return cmd_thread( &last ); }
271 #if ! defined(NO_STDOUT)
272 if ( ! strcmp( token, "stress" ) ) { return cmd_stress( &last ); }
274 #if ! defined(MINIMUM)
275 if ( ! strcmp( token, "learn" ) ) { return cmd_learn( ptree, &last ); }
278 str_error = str_bad_cmdline;
284 static int CONV proce_csalan( tree_t * restrict ptree )
289 token = strtok_r( str_cmdline, str_delimiters, &last );
291 if ( token == NULL ) { return 1; }
292 if ( *token == ach_turn[client_turn] && is_move( token+1 ) )
297 token = strtok_r( NULL, str_delimiters, &last );
298 if ( token == NULL || *token != 'T' )
300 str_error = str_bad_cmdline;
304 l = strtol( token+1, &ptr, 0 );
305 if ( token+1 == ptr || l == LONG_MAX || l < 1 )
307 str_error = str_bad_cmdline;
311 adjust_time( (unsigned int)l, client_turn );
312 Out( " elapsed: b%u, w%u\n", sec_b_total, sec_w_total );
315 if ( *token == ach_turn[Flip(client_turn)] && is_move( token+1 ) )
317 return cmd_usrmove( ptree, token+1, &last );
319 if ( ! strcmp( token, str_resign ) ) { return cmd_resign( ptree, &last ); }
320 if ( ! strcmp( token, "#WIN" )
321 || ! strcmp( token, "#LOSE" )
322 || ! strcmp( token, "#DRAW" )
323 || ! strcmp( token, "#CHUDAN" ) )
325 if ( game_status & ( flag_thinking | flag_pondering | flag_puzzling ) )
327 game_status |= flag_suspend;
331 if ( sckt_out( sckt_csa, "LOGOUT\n" ) < 0 ) { return -1; }
332 if ( sckt_recv_all( sckt_csa ) < 0 ) { return -1; }
336 if ( client_ngame == client_max_game ) { return cmd_quit(); }
338 return client_next_game( ptree, client_str_addr, (int)client_port );
347 static int CONV proce_mnj( tree_t * restrict ptree )
353 token = strtok_r( str_cmdline, str_delimiters, &last );
354 if ( token == NULL ) { return 1; }
356 if ( ! strcmp( token, "new" ) )
358 iret = cmd_suspend();
359 if ( iret != 1 ) { return iret; }
362 iret = cmd_new( ptree, &last );
363 if ( iret < 0 ) { return iret; }
365 moves_ignore[0] = MOVE_NA;
366 return analyze( ptree );
368 if ( ! strcmp( token, "ignore" ) ) { return cmd_mnjignore( ptree, &last ); }
369 if ( ! strcmp( token, "idle" ) ) { return cmd_suspend(); }
370 if ( ! strcmp( token, "alter" ) ) { return cmd_mnjmove( ptree, &last, 1 ); }
371 if ( ! strcmp( token, "retract" ) )
375 const char *str = strtok_r( NULL, str_delimiters, &last );
378 str_error = str_bad_cmdline;
381 l = strtol( str, &ptr, 0 );
382 if ( ptr == str || (long)NUM_UNMAKE < l )
384 str_error = str_bad_cmdline;
388 return cmd_mnjmove( ptree, &last, (int)l );
390 if ( ! strcmp( token, "move" ) ) { return cmd_mnjmove( ptree, &last, 0 ); }
392 str_error = str_bad_cmdline;
398 cmd_mnjignore( tree_t *restrict ptree, char **lasts )
407 token = strtok_r( NULL, str_delimiters, lasts );
410 str_error = str_bad_cmdline;
413 lid = strtol( token, &ptr, 0 );
414 if ( ptr == token || lid == LONG_MAX || lid < 1 )
416 str_error = str_bad_cmdline;
420 AbortDifficultCommand;
422 for ( i = 0; ; i += 1 )
424 token = strtok_r( NULL, str_delimiters, lasts );
425 if ( token == NULL ) { break; }
427 if ( interpret_CSA_move( ptree, &move, token ) < 0 ) { return -1; }
429 moves_ignore[i] = move;
433 str_error = str_bad_cmdline;
436 mnj_posi_id = (int)lid;
437 moves_ignore[i] = MOVE_NA;
439 return analyze( ptree );
444 cmd_mnjmove( tree_t * restrict ptree, char **lasts, int num_alter )
446 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
447 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
453 if ( sckt_mnj == SCKT_NULL || str1 == NULL || str2 == NULL )
455 str_error = str_bad_cmdline;
459 lid = strtol( str2, &ptr, 0 );
460 if ( ptr == str2 || lid == LONG_MAX || lid < 1 )
462 str_error = str_bad_cmdline;
466 AbortDifficultCommand;
470 iret = unmake_move_root( ptree );
471 if ( iret < 0 ) { return iret; }
476 iret = interpret_CSA_move( ptree, &move, str1 );
477 if ( iret < 0 ) { return iret; }
479 iret = get_elapsed( &time_turn_start );
480 if ( iret < 0 ) { return iret; }
482 mnj_posi_id = (int)lid;
484 iret = make_move_root( ptree, move, ( flag_time | flag_rep
485 | flag_detect_hang ) );
486 if ( iret < 0 ) { return iret; }
488 # if ! defined(NO_STDOUT)
489 iret = out_board( ptree, stdout, 0, 0 );
490 if ( iret < 0 ) { return iret; }
493 moves_ignore[0] = MOVE_NA;
494 return analyze( ptree );
500 static int CONV proce_usi( tree_t * restrict ptree )
506 token = strtok_r( str_cmdline, str_delimiters, &lasts );
507 if ( token == NULL ) { return 1; }
509 if ( ! strcmp( token, "usi" ) )
511 USIOut( "id name %s\n", str_myname );
512 USIOut( "id author Kunihito Hoki\n" );
517 if ( ! strcmp( token, "isready" ) )
519 USIOut( "readyok\n", str_myname );
523 if ( ! strcmp( token, "echo" ) )
525 USIOut( "%s\n", lasts );
529 if ( ! strcmp( token, "ignore_moves" ) )
531 return usi_ignore( ptree, &lasts );
534 if ( ! strcmp( token, "genmove_probability" ) )
536 if ( get_elapsed( &time_start ) < 0 ) { return -1; }
537 return usi_root_list( ptree );
540 if ( ! strcmp( token, "go" ) )
542 iret = usi_go( ptree, &lasts );
543 moves_ignore[0] = MOVE_NA;
547 if ( ! strcmp( token, "stop" ) ) { return cmd_move_now(); }
548 if ( ! strcmp( token, "position" ) ) { return usi_posi( ptree, &lasts ); }
549 if ( ! strcmp( token, "quit" ) ) { return cmd_quit(); }
551 str_error = str_bad_cmdline;
557 usi_ignore( tree_t * restrict ptree, char **lasts )
564 AbortDifficultCommand;
566 for ( i = 0; ; i += 1 )
568 token = strtok_r( NULL, str_delimiters, lasts );
569 if ( token == NULL ) { break; }
571 if ( usi2csa( ptree, token, str_buf ) < 0 ) { return -1; }
572 if ( interpret_CSA_move( ptree, &move, str_buf ) < 0 ) { return -1; }
574 moves_ignore[i] = move;
577 moves_ignore[i] = MOVE_NA;
584 usi_go( tree_t * restrict ptree, char **lasts )
591 AbortDifficultCommand;
593 if ( game_status & mask_game_end )
595 str_error = str_game_ended;
599 token = strtok_r( NULL, str_delimiters, lasts );
601 if ( ! strcmp( token, "book" ) )
603 AbortDifficultCommand;
604 if ( usi_book( ptree ) < 0 ) { return -1; }
610 if ( ! strcmp( token, "infinite" ) )
612 usi_byoyomi = UINT_MAX;
613 depth_limit = PLY_MAX;
614 node_limit = UINT64_MAX;
615 sec_limit_depth = UINT_MAX;
617 else if ( ! strcmp( token, "byoyomi" ) )
619 token = strtok_r( NULL, str_delimiters, lasts );
622 str_error = str_bad_cmdline;
626 l = strtol( token, &ptr, 0 );
627 if ( ptr == token || l > UINT_MAX || l < 1 )
629 str_error = str_bad_cmdline;
633 usi_byoyomi = (unsigned int)l;
634 depth_limit = PLY_MAX;
635 node_limit = UINT64_MAX;
636 sec_limit_depth = UINT_MAX;
639 str_error = str_bad_cmdline;
644 if ( get_elapsed( &time_turn_start ) < 0 ) { return -1; }
646 iret = com_turn_start( ptree, 0 );
648 if ( str_error == str_no_legal_move ) { USIOut( "bestmove resign\n" ); }
657 usi_posi( tree_t * restrict ptree, char **lasts )
663 AbortDifficultCommand;
665 moves_ignore[0] = MOVE_NA;
667 token = strtok_r( NULL, str_delimiters, lasts );
668 if ( strcmp( token, "startpos" ) )
670 str_error = str_bad_cmdline;
674 if ( ini_game( ptree, &min_posi_no_handicap,
675 flag_history, NULL, NULL ) < 0 ) { return -1; }
677 token = strtok_r( NULL, str_delimiters, lasts );
678 if ( token == NULL ) { return 1; }
680 if ( strcmp( token, "moves" ) )
682 str_error = str_bad_cmdline;
688 token = strtok_r( NULL, str_delimiters, lasts );
689 if ( token == NULL ) { break; }
691 if ( usi2csa( ptree, token, str_buf ) < 0 ) { return -1; }
692 if ( interpret_CSA_move( ptree, &move, str_buf ) < 0 ) { return -1; }
693 if ( make_move_root( ptree, move, ( flag_history | flag_time
695 | flag_detect_hang ) ) < 0 )
701 if ( get_elapsed( &time_turn_start ) < 0 ) { return -1; }
708 static int CONV cmd_move_now( void )
710 if ( game_status & flag_thinking ) { game_status |= flag_move_now; }
717 cmd_usrmove( tree_t * restrict ptree, const char *str_move, char **lasts )
725 if ( game_status & mask_game_end )
727 str_error = str_game_ended;
731 if ( game_status & flag_thinking )
733 str_error = str_busy_think;
737 str = strtok_r( NULL, str_delimiters, lasts );
738 if ( str == NULL ) { lelapsed = 0; }
742 str_error = str_bad_cmdline;
746 lelapsed = strtol( str, &ptr, 0 );
747 if ( ptr == str || lelapsed == LONG_MAX || lelapsed < 1 )
749 str_error = str_bad_cmdline;
754 if ( game_status & ( flag_pondering | flag_puzzling ) )
758 for ( i = 0; i < ponder_nmove; i++ )
760 if ( ! strcmp( str_move, str_CSA_move(ponder_move_list[i]) ) )
765 if ( i == ponder_nmove )
768 if ( sckt_csa != SCKT_NULL ) { AbortDifficultCommand; }
771 #if defined(CSASHOGI)
772 AbortDifficultCommand;
774 str_error = str_illegal_move;
779 if ( ( game_status & flag_puzzling )
780 || strcmp( str_move, str_CSA_move(ponder_move) ) )
782 ponder_move = MOVE_PONDER_FAILED;
783 game_status |= flag_quit_ponder;
787 iret = update_time( Flip(root_turn) );
788 if ( iret < 0 ) { return iret; }
791 adjust_time( (unsigned int)lelapsed, Flip(root_turn) );
794 out_CSA( ptree, &record_game, ponder_move );
796 game_status &= ~flag_pondering;
797 game_status |= flag_thinking;
801 set_search_limit_time( root_turn );
803 OutCsaShogi( "info ponder end\n" );
805 str = str_time_symple( time_turn_start - time_start );
806 Out( " %6s MOVE PREDICTION HIT\n"
807 " elapsed: b%u, w%u\n", str, sec_b_total, sec_w_total );
812 iret = interpret_CSA_move( ptree, &move, str_move );
813 if ( iret < 0 ) { return iret; }
814 move_evasion_pchk = 0;
815 iret = make_move_root( ptree, move, ( flag_rep | flag_history | flag_time
816 | flag_detect_hang ) );
821 if ( sckt_csa != SCKT_NULL )
823 if ( move_evasion_pchk )
825 str = str_CSA_move( move_evasion_pchk );
826 iret = sckt_out( sckt_csa, "%c%s\n",
827 ach_turn[Flip(root_turn)], str );
828 if ( iret < 0 ) { return iret; }
830 return cmd_suspend();
834 if ( move_evasion_pchk )
836 str = str_CSA_move( move_evasion_pchk );
837 #if defined(CSASHOGI)
838 OutCsaShogi( "move%s\n", str );
839 return cmd_suspend();
841 snprintf( str_message, SIZE_MESSAGE, "perpetual check (%c%s)",
842 ach_turn[Flip(root_turn)], str );
843 str_error = str_message;
851 if ( lelapsed ) { adjust_time( (unsigned int)lelapsed, Flip(root_turn) ); }
852 Out( " elapsed: b%u, w%u\n", sec_b_total, sec_w_total );
855 if ( sckt_csa != SCKT_NULL && ( game_status & flag_mated ) )
857 iret = sckt_out( sckt_csa, "%%TORYO\n" );
858 if ( iret < 0 ) { return iret; }
862 if ( ! ( game_status & mask_game_end ) )
864 iret = com_turn_start( ptree, 0 );
865 if ( iret < 0 ) { return iret; }
872 static int CONV cmd_beep( char **lasts )
874 const char *str = strtok_r( NULL, str_delimiters, lasts );
877 str_error = str_bad_cmdline;
881 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nobeep; }
882 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nobeep; }
884 str_error = str_bad_cmdline;
892 static int CONV cmd_peek( char **lasts )
894 const char *str = strtok_r( NULL, str_delimiters, lasts );
898 str_error = str_bad_cmdline;
902 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nopeek; }
903 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nopeek; }
905 str_error = str_bad_cmdline;
913 static int CONV cmd_stdout( char **lasts )
915 const char *str = strtok_r( NULL, str_delimiters, lasts );
919 str_error = str_bad_cmdline;
923 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nostdout; }
924 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nostdout; }
926 str_error = str_bad_cmdline;
934 static int CONV cmd_newlog( char **lasts )
936 const char *str = strtok_r( NULL, str_delimiters, lasts );
940 str_error = str_bad_cmdline;
944 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nonewlog; }
945 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nonewlog; }
947 str_error = str_bad_cmdline;
955 static int CONV cmd_ponder( char **lasts )
957 const char *str = strtok_r( NULL, str_delimiters, lasts );
961 str_error = str_bad_cmdline;
965 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_noponder; }
966 else if ( ! strcmp( str, str_off ) )
968 if ( game_status & ( flag_pondering | flag_puzzling ) )
970 game_status |= flag_quit_ponder;
972 game_status |= flag_noponder;
975 str_error = str_bad_cmdline;
983 #if ! defined(NO_STDOUT)
984 static int CONV cmd_stress( char **lasts )
986 const char *str = strtok_r( NULL, str_delimiters, lasts );
990 str_error = str_bad_cmdline;
994 if ( ! strcmp( str, str_on ) ) { game_status &= ~flag_nostress; }
995 else if ( ! strcmp( str, str_off ) ) { game_status |= flag_nostress; }
997 str_error = str_bad_cmdline;
1007 #if defined(MINIMUM)
1008 cmd_book( char **lasts )
1010 cmd_book( tree_t * restrict ptree, char **lasts )
1013 const char *str = strtok_r( NULL, str_delimiters, lasts );
1018 str_error = str_bad_cmdline;
1021 if ( ! strcmp( str, str_on ) ) { iret = book_on(); }
1022 else if ( ! strcmp( str, str_off ) ) { iret = book_off(); }
1023 else if ( ! strcmp( str, "narrow" ) ) { game_status |= flag_narrow_book; }
1024 else if ( ! strcmp( str, "wide" ) ) { game_status &= ~flag_narrow_book; }
1025 #if ! defined(MINIMUM)
1026 else if ( ! strcmp( str, "create" ) )
1028 AbortDifficultCommand;
1030 iret = book_create( ptree );
1031 if ( iret < 0 ) { return iret; }
1033 iret = ini_game( ptree, &min_posi_no_handicap, flag_history,
1035 if ( iret < 0 ) { return iret; }
1037 iret = get_elapsed( &time_turn_start );
1041 str_error = str_bad_cmdline;
1049 static int CONV cmd_display( tree_t * restrict ptree, char **lasts )
1051 const char *str = strtok_r( NULL, str_delimiters, lasts );
1058 l = strtol( str, &ptr, 0 );
1061 str_error = str_bad_cmdline;
1064 if ( l == 1 ) { game_status &= ~flag_reverse; }
1065 else if ( l == 2 ) { game_status |= flag_reverse; }
1067 str_error = str_bad_cmdline;
1073 iret = out_board( ptree, stdout, 0, 0 );
1074 if ( iret < 0 ) { return iret; }
1075 #if ! defined(NO_LOGGING)
1076 iret = out_board( ptree, pf_log, 0, 0 );
1077 if ( iret < 0 ) { return iret; }
1085 static int CONV cmd_ping( void )
1087 OutCsaShogi( "pong\n" );
1093 static int CONV cmd_hash( char **lasts )
1095 const char *str = strtok_r( NULL, str_delimiters, lasts );
1101 str_error = str_bad_cmdline;
1105 l = strtol( str, &ptr, 0 );
1106 if ( ptr == str || l == LONG_MAX || l < 1 || l > 31 )
1108 str_error = str_bad_cmdline;
1112 AbortDifficultCommand;
1114 log2_ntrans_table = (int)l;
1115 memory_free( (void *)ptrans_table_orig );
1116 return ini_trans_table();
1120 static int CONV cmd_limit( char **lasts )
1122 const char *str = strtok_r( NULL, str_delimiters, lasts );
1128 str_error = str_bad_cmdline;
1132 AbortDifficultCommand;
1134 if ( ! strcmp( str, "depth" ) )
1136 str = strtok_r( NULL, str_delimiters, lasts );
1139 str_error = str_bad_cmdline;
1142 l1 = strtol( str, &ptr, 0 );
1143 if ( ptr == str || l1 == LONG_MAX || l1 < 1 )
1145 str_error = str_bad_cmdline;
1148 sec_limit_up = UINT_MAX;
1149 node_limit = UINT64_MAX;
1150 depth_limit = (int)l1;
1152 else if ( ! strcmp( str, "nodes" ) )
1154 str = strtok_r( NULL, str_delimiters, lasts );
1157 str_error = str_bad_cmdline;
1160 l1 = strtol( str, &ptr, 0 );
1161 if ( ptr == str || l1 == LONG_MAX || l1 < 1 )
1163 str_error = str_bad_cmdline;
1166 sec_limit_up = UINT_MAX;
1167 depth_limit = PLY_MAX;
1168 node_limit = (uint64_t)l1;
1170 else if ( ! strcmp( str, "time" ) )
1172 str = strtok_r( NULL, str_delimiters, lasts );
1175 str_error = str_bad_cmdline;
1179 if ( ! strcmp( str, "extendable" ) )
1181 game_status |= flag_time_extendable;
1183 else if ( ! strcmp( str, "strict" ) )
1185 game_status &= ~flag_time_extendable;
1188 l1 = strtol( str, &ptr, 0 );
1189 if ( ptr == str || l1 == LONG_MAX || l1 < 0 )
1191 str_error = str_bad_cmdline;
1195 str = strtok_r( NULL, str_delimiters, lasts );
1198 str_error = str_bad_cmdline;
1201 l2 = strtol( str, &ptr, 0 );
1202 if ( ptr == str || l2 == LONG_MAX || l2 < 0 )
1204 str_error = str_bad_cmdline;
1208 str = strtok_r( NULL, str_delimiters, lasts );
1209 if ( ! str ) { l3 = -1; }
1211 l3 = strtol( str, &ptr, 0 );
1212 if ( ptr == str || l3 >= PLY_MAX || l3 < -1 )
1214 str_error = str_bad_cmdline;
1219 if ( ! ( l1 | l2 ) ) { l2 = 1; }
1221 depth_limit = PLY_MAX;
1222 node_limit = UINT64_MAX;
1223 sec_limit = (unsigned int)l1 * 60U;
1224 sec_limit_up = (unsigned int)l2;
1225 if ( l3 == -1 ) { sec_limit_depth = UINT_MAX; }
1226 else { sec_limit_depth = (unsigned int)l3; }
1230 str_error = str_bad_cmdline;
1239 cmd_read( tree_t * restrict ptree, char **lasts )
1241 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1242 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1243 const char *str3 = strtok_r( NULL, str_delimiters, lasts );
1244 const char *str_tmp;
1245 FILE *pf_src, *pf_dest;
1246 char str_file[SIZE_FILENAME];
1252 flag = flag_history | flag_rep | flag_detect_hang;
1258 str_error = str_bad_cmdline;
1264 if ( ! strcmp( str2, "t" ) ) { flag |= flag_time; }
1265 else if ( strcmp( str2, "nil" ) )
1267 str_error = str_bad_cmdline;
1274 l = strtol( str3, &ptr, 0 );
1275 if ( ptr == str3 || l == LONG_MAX || l < 1 )
1277 str_error = str_bad_cmdline;
1280 moves = (unsigned int)l - 1U;
1283 AbortDifficultCommand;
1285 if ( ! strcmp( str1, "." ) )
1287 str_tmp = "game.cs_";
1289 #if defined(NO_LOGGING)
1290 strncpy( str_file, "game.csa", SIZE_FILENAME-1 );
1292 snprintf( str_file, SIZE_FILENAME, "%s/game%03d.csa",
1293 str_dir_logs, record_num );
1295 pf_dest = file_open( str_tmp, "w" );
1296 if ( pf_dest == NULL ) { return -2; }
1298 pf_src = file_open( str_file, "r" );
1299 if ( pf_src == NULL )
1301 file_close( pf_dest );
1305 while ( ( c = getc(pf_src) ) != EOF ) { putc( c, pf_dest ); }
1307 iret = file_close( pf_src );
1310 file_close( pf_dest );
1314 iret = file_close( pf_dest );
1315 if ( iret < 0 ) { return iret; }
1321 iret = read_record( ptree, str1, moves, flag );
1322 if ( iret < 0 ) { return iret; }
1324 iret = get_elapsed( &time_turn_start );
1325 if ( iret < 0 ) { return iret; }
1327 if ( str_tmp && remove( str_tmp ) )
1329 out_warning( "remove() failed." );
1337 static int CONV cmd_resign( tree_t * restrict ptree, char **lasts )
1339 const char *str = strtok_r( NULL, str_delimiters, lasts );
1343 if ( str == NULL || *str == 'T' )
1345 AbortDifficultCommand;
1347 if ( game_status & mask_game_end ) { return 1; }
1349 game_status |= flag_resigned;
1350 update_time( root_turn );
1351 out_CSA( ptree, &record_game, MOVE_RESIGN );
1354 l = strtol( str, &ptr, 0 );
1355 if ( ptr == str || l == LONG_MAX || l < MT_CAP_PAWN )
1357 str_error = str_bad_cmdline;
1360 resign_threshold = (int)l;
1367 static int CONV cmd_move( tree_t * restrict ptree, char **lasts )
1369 const char *str = strtok_r( NULL, str_delimiters, lasts );
1375 if ( game_status & mask_game_end )
1377 str_error = str_game_ended;
1381 AbortDifficultCommand;
1385 iret = get_elapsed( &time_turn_start );
1386 if ( iret < 0 ) { return iret; }
1388 return com_turn_start( ptree, 0 );
1391 l = strtol( str, &ptr, 0 );
1392 if ( str != ptr && l != LONG_MAX && l >= 1 && *ptr == '\0' )
1394 for ( i = 0; i < l; i += 1 )
1396 if ( game_status & ( flag_move_now | mask_game_end ) ) { break; }
1398 iret = get_elapsed( &time_turn_start );
1399 if ( iret < 0 ) { return iret; }
1401 iret = com_turn_start( ptree, 0 );
1402 if ( iret < 0 ) { return iret; }
1409 iret = interpret_CSA_move( ptree, &move, str );
1410 if ( iret < 0 ) { return iret; }
1412 iret = get_elapsed( &time_turn_start );
1413 if ( iret < 0 ) { return iret; }
1415 iret = make_move_root( ptree, move,
1416 ( flag_history | flag_time | flag_rep
1417 | flag_detect_hang ) );
1418 if ( iret < 0 ) { return iret; }
1420 str = strtok_r( NULL, str_delimiters, lasts );
1422 } while ( str != NULL );
1428 static int CONV cmd_new( tree_t * restrict ptree, char **lasts )
1430 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1431 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1432 const min_posi_t *pmp;
1433 min_posi_t min_posi;
1436 AbortDifficultCommand;
1440 memset( &min_posi.asquare, empty, nsquare );
1441 min_posi.hand_black = min_posi.hand_white = 0;
1442 iret = read_board_rep1( str1, &min_posi );
1443 if ( iret < 0 ) { return iret; }
1447 if ( ! strcmp( str2, "-" ) ) { min_posi.turn_to_move = white; }
1448 else if ( ! strcmp( str2, "+" ) ) { min_posi.turn_to_move = black; }
1450 str_error = str_bad_cmdline;
1454 else { min_posi.turn_to_move = black; }
1458 else { pmp = &min_posi_no_handicap; }
1460 iret = ini_game( ptree, pmp, flag_history, NULL, NULL );
1461 if ( iret < 0 ) { return iret; }
1463 return get_elapsed( &time_turn_start );
1467 static int CONV cmd_outmove( tree_t * restrict ptree )
1469 const char *str_move;
1471 unsigned int move_list[ MAX_LEGAL_MOVES ];
1474 AbortDifficultCommand;
1476 if ( game_status & mask_game_end )
1478 Out( "NO LEGAL MOVE\n" );
1479 DFPNOut( "NO LEGAL MOVE\n" );
1483 n = gen_legal_moves( ptree, move_list, 0 );
1486 for ( c = i = 0; i < n; i += 1 )
1488 str_move = str_CSA_move(move_list[i]);
1490 if ( i && ( i % 10 ) == 0 )
1492 Out( "%s\n", buffer );
1493 DFPNOut( "%s ", buffer );
1494 memcpy( buffer, str_move, 6 );
1500 memcpy( buffer + c + 1, str_move, 6 );
1504 memcpy( buffer + c, str_move, 6 );
1509 Out( "%s\n", buffer );
1510 DFPNOut( "%s\n", buffer );
1516 static int CONV cmd_problem( tree_t * restrict ptree, char **lasts )
1518 const char *str = strtok_r( NULL, str_delimiters, lasts );
1521 unsigned int nposition;
1527 AbortDifficultCommand;
1532 if ( str != NULL && ! strcmp( str, "mate" ) )
1535 str = strtok_r( NULL, str_delimiters, lasts );
1541 l = strtol( str, &ptr, 0 );
1542 if ( ptr == str || l == LONG_MAX || l < 1 )
1544 str_error = str_bad_cmdline;
1547 nposition = (unsigned int)l;
1549 else { nposition = UINT_MAX; }
1552 iret = record_open( &record_problems, "problem.csa", mode_read, NULL, NULL );
1553 if ( iret < 0 ) { return iret; }
1556 iret = is_mate ? solve_mate_problems( ptree, nposition )
1557 : solve_problems( ptree, nposition );
1559 iret = solve_problems( ptree, nposition );
1564 record_close( &record_problems );
1568 iret = record_close( &record_problems );
1569 if ( iret < 0 ) { return iret; }
1571 return get_elapsed( &time_turn_start );
1575 static int CONV cmd_quit( void )
1577 game_status |= flag_quit;
1582 static int CONV cmd_suspend( void )
1584 if ( game_status & ( flag_pondering | flag_puzzling ) )
1586 game_status |= flag_quit_ponder;
1590 game_status |= flag_suspend;
1595 static int CONV cmd_time( char **lasts )
1597 const char *str = strtok_r( NULL, str_delimiters, lasts );
1602 str_error = str_bad_cmdline;
1605 else if ( ! strcmp( str, "response" ) )
1608 str = strtok_r( NULL, str_delimiters, lasts );
1611 str_error = str_bad_cmdline;
1614 l = strtol( str, &ptr, 0 );
1615 if ( ptr == str || l == LONG_MAX || l < 0 || l > 1000 )
1617 str_error = str_bad_cmdline;
1620 time_response = (unsigned int)l;
1623 else if ( ! strcmp( str, "remain" ) )
1627 str = strtok_r( NULL, str_delimiters, lasts );
1630 str_error = str_bad_cmdline;
1633 l1 = strtol( str, &ptr, 0 );
1634 if ( ptr == str || l1 == LONG_MAX || l1 < 0 )
1636 str_error = str_bad_cmdline;
1640 str = strtok_r( NULL, str_delimiters, lasts );
1643 str_error = str_bad_cmdline;
1646 l2 = strtol( str, &ptr, 0 );
1647 if ( ptr == str || l2 == LONG_MAX || l2 < 0 )
1649 str_error = str_bad_cmdline;
1653 if ( sec_limit_up == UINT_MAX )
1655 str_error = str_bad_cmdline;
1659 return reset_time( (unsigned int)l1, (unsigned int)l2 );
1662 str_error = str_bad_cmdline;
1667 #if !defined(MINIMUM)
1668 /* learn (ini|no-ini) steps games iterations tlp1 tlp2 */
1669 static int CONV cmd_learn( tree_t * restrict ptree, char **lasts )
1671 const char *str1 = strtok_r( NULL, str_delimiters, lasts );
1672 const char *str2 = strtok_r( NULL, str_delimiters, lasts );
1673 const char *str3 = strtok_r( NULL, str_delimiters, lasts );
1674 const char *str4 = strtok_r( NULL, str_delimiters, lasts );
1676 const char *str5 = strtok_r( NULL, str_delimiters, lasts );
1677 const char *str6 = strtok_r( NULL, str_delimiters, lasts );
1681 unsigned int max_games;
1682 int is_ini, nsteps, max_iterations, nworker1, nworker2, iret;
1686 str_error = str_bad_cmdline;
1689 if ( ! strcmp( str1, "ini" ) ) { is_ini = 1; }
1690 else if ( ! strcmp( str1, "no-ini" ) ) { is_ini = 0; }
1692 str_error = str_bad_cmdline;
1696 max_games = UINT_MAX;
1697 max_iterations = INT_MAX;
1698 nworker1 = nworker2 = nsteps = 1;
1702 l = strtol( str2, &ptr, 0 );
1703 if ( ptr == str2 || l == LONG_MAX || l < 1 )
1705 str_error = str_bad_cmdline;
1713 l = strtol( str3, &ptr, 0 );
1714 if ( ptr == str3 || l == LONG_MAX || l == LONG_MIN )
1716 str_error = str_bad_cmdline;
1719 if ( l > 0 ) { max_games = (unsigned int)l; }
1724 l = strtol( str4, &ptr, 0 );
1725 if ( ptr == str4 || l == LONG_MAX || l == LONG_MIN )
1727 str_error = str_bad_cmdline;
1730 if ( l > 0 ) { max_iterations = (int)l; }
1736 l = strtol( str5, &ptr, 0 );
1737 if ( ptr == str5 || l > TLP_MAX_THREADS || l < 1 )
1739 str_error = str_bad_cmdline;
1747 l = strtol( str6, &ptr, 0 );
1748 if ( ptr == str6 || l > TLP_MAX_THREADS || l < 1 )
1750 str_error = str_bad_cmdline;
1757 AbortDifficultCommand;
1759 log2_ntrans_table = 12;
1761 memory_free( (void *)ptrans_table_orig );
1763 iret = ini_trans_table();
1764 if ( iret < 0 ) { return iret; }
1766 iret = learn( ptree, is_ini, nsteps, max_games, max_iterations,
1767 nworker1, nworker2 );
1768 if ( iret < 0 ) { return -1; }
1770 iret = ini_game( ptree, &min_posi_no_handicap, flag_history, NULL, NULL );
1771 if ( iret < 0 ) { return -1; }
1773 iret = get_elapsed( &time_turn_start );
1774 if ( iret < 0 ) { return iret; }
1778 #endif /* MINIMUM */
1782 static int CONV cmd_mpv( char **lasts )
1784 const char *str = strtok_r( NULL, str_delimiters, lasts );
1790 str_error = str_bad_cmdline;
1793 else if ( ! strcmp( str, "num" ) )
1795 str = strtok_r( NULL, str_delimiters, lasts );
1798 str_error = str_bad_cmdline;
1801 l = strtol( str, &ptr, 0 );
1802 if ( ptr == str || l == LONG_MAX || l < 1 || l > MPV_MAX_PV )
1804 str_error = str_bad_cmdline;
1808 AbortDifficultCommand;
1814 else if ( ! strcmp( str, "width" ) )
1816 str = strtok_r( NULL, str_delimiters, lasts );
1819 str_error = str_bad_cmdline;
1822 l = strtol( str, &ptr, 0 );
1823 if ( ptr == str || l == LONG_MAX || l < MT_CAP_PAWN )
1825 str_error = str_bad_cmdline;
1829 AbortDifficultCommand;
1836 str_error = str_bad_cmdline;
1843 static int CONV cmd_dfpn( tree_t * restrict ptree, char **lasts )
1845 const char *str = strtok_r( NULL, str_delimiters, lasts );
1849 str_error = str_bad_cmdline;
1852 else if ( ! strcmp( str, "hash" ) )
1857 str = strtok_r( NULL, str_delimiters, lasts );
1860 str_error = str_bad_cmdline;
1863 l = strtol( str, &ptr, 0 );
1864 if ( ptr == str || l == LONG_MAX || l < 1 )
1866 str_error = str_bad_cmdline;
1870 AbortDifficultCommand;
1872 dfpn_hash_log2 = (unsigned int)l;
1873 return dfpn_ini_hash();
1875 else if ( ! strcmp( str, "go" ) )
1877 AbortDifficultCommand;
1879 return dfpn( ptree, root_turn, 1 );
1881 else if ( ! strcmp( str, "connect" ) )
1889 str = strtok_r( NULL, str_delimiters, lasts );
1890 if ( ! str || ! strcmp( str, "." ) ) { str = "127.0.0.1"; }
1891 strncpy( str_addr, str, 255 );
1892 str_addr[255] = '\0';
1894 str = strtok_r( NULL, str_delimiters, lasts );
1895 if ( ! str || ! strcmp( str, "." ) ) { str = "4083"; }
1896 l = strtol( str, &ptr, 0 );
1897 if ( ptr == str || l == LONG_MAX || l < 0 || l > USHRT_MAX )
1899 str_error = str_bad_cmdline;
1904 str = strtok_r( NULL, str_delimiters, lasts );
1905 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza1"; }
1906 strncpy( str_id, str, 255 );
1909 AbortDifficultCommand;
1911 dfpn_sckt = sckt_connect( str_addr, port );
1912 if ( dfpn_sckt == SCKT_NULL ) { return -2; }
1914 str_buffer_cmdline[0] = '\0';
1915 DFPNOut( "Worker: %s\n", str_id );
1920 str_error = str_bad_cmdline;
1927 static int CONV cmd_thread( char **lasts )
1929 const char *str = strtok_r( NULL, str_delimiters, lasts );
1933 str_error = str_bad_cmdline;
1936 else if ( ! strcmp( str, "num" ) )
1941 str = strtok_r( NULL, str_delimiters, lasts );
1944 str_error = str_bad_cmdline;
1947 l = strtol( str, &ptr, 0 );
1948 if ( ptr == str || l == LONG_MAX || l < 1 || l > TLP_MAX_THREADS )
1950 str_error = str_bad_cmdline;
1958 if ( game_status & ( flag_thinking | flag_pondering | flag_puzzling ) )
1965 str_error = str_bad_cmdline;
1971 #if defined(DFPN_CLIENT)
1972 static int CONV cmd_dfpn_client( tree_t * restrict ptree, char **lasts )
1978 AbortDifficultCommand;
1980 str = strtok_r( NULL, str_delimiters, lasts );
1981 if ( ! str || ! strcmp( str, "." ) ) { str = "127.0.0.1"; }
1982 strncpy( dfpn_client_str_addr, str, 255 );
1983 dfpn_client_str_addr[255] = '\0';
1985 str = strtok_r( NULL, str_delimiters, lasts );
1986 if ( ! str || ! strcmp( str, "." ) ) { str = "4083"; }
1987 dfpn_client_port = strtol( str, &ptr, 0 );
1988 if ( ptr == str || dfpn_client_port == LONG_MAX || dfpn_client_port < 0
1989 || dfpn_client_port > USHRT_MAX )
1991 str_error = str_bad_cmdline;
1995 Out( "DFPN Server: %s %d\n", dfpn_client_str_addr, dfpn_client_port );
1997 iret = ini_game( ptree, &min_posi_no_handicap, flag_history, NULL, NULL );
1998 if ( iret < 0 ) { return iret; }
2000 if ( dfpn_client_sckt == SCKT_NULL )
2002 str_error = "Check network status.";
2006 return get_elapsed( &time_turn_start );
2011 #if defined(CSA_LAN)
2012 static int CONV cmd_connect( tree_t * restrict ptree, char **lasts )
2018 str = strtok_r( NULL, str_delimiters, lasts );
2019 if ( ! str || ! strcmp( str, "." ) ) { str = "gserver.computer-shogi.org"; }
2020 strncpy( client_str_addr, str, 255 );
2021 client_str_addr[255] = '\0';
2023 str = strtok_r( NULL, str_delimiters, lasts );
2024 if ( ! str || ! strcmp( str, "." ) ) { str = "4081"; }
2025 client_port = strtol( str, &ptr, 0 );
2026 if ( ptr == str || client_port == LONG_MAX || client_port < 0
2027 || client_port > USHRT_MAX )
2029 str_error = str_bad_cmdline;
2033 str = strtok_r( NULL, str_delimiters, lasts );
2034 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza_test"; }
2035 strncpy( client_str_id, str, 255 );
2036 client_str_id[255] = '\0';
2038 str = strtok_r( NULL, " \t", lasts );
2039 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza_test"; }
2040 strncpy( client_str_pwd, str, 255 );
2041 client_str_pwd[255] = '\0';
2043 str = strtok_r( NULL, str_delimiters, lasts );
2044 if ( ! str || ! strcmp( str, "." ) ) { client_max_game = INT_MAX; }
2046 max_games = strtol( str, &ptr, 0 );
2047 if ( ptr == str || max_games == LONG_MAX || max_games < 1 )
2049 str_error = str_bad_cmdline;
2052 client_max_game = max_games;
2055 AbortDifficultCommand;
2059 return client_next_game( ptree, client_str_addr, (int)client_port );
2063 static int CONV cmd_sendpv( char **lasts )
2065 const char *str = strtok_r( NULL, str_delimiters, lasts );
2069 str_error = str_bad_cmdline;
2073 if ( ! strcmp( str, str_off ) ) { game_status &= ~flag_sendpv; }
2074 else if ( ! strcmp( str, str_on ) ) { game_status |= flag_sendpv; }
2076 str_error = str_bad_cmdline;
2085 #if defined(MNJ_LAN)
2086 /* mnj sd seed addr port name factor stable_depth */
2087 static int CONV cmd_mnj( char **lasts )
2089 char client_str_addr[256];
2090 char client_str_id[256];
2095 int client_port, sd;
2098 str = strtok_r( NULL, str_delimiters, lasts );
2101 str_error = str_bad_cmdline;
2104 l = strtol( str, &ptr, 0 );
2105 if ( ptr == str || l == LONG_MAX || l < 0 )
2107 str_error = str_bad_cmdline;
2113 str = strtok_r( NULL, str_delimiters, lasts );
2116 str_error = str_bad_cmdline;
2119 l = strtol( str, &ptr, 0 );
2120 if ( ptr == str || l == LONG_MAX || l < 0 )
2122 str_error = str_bad_cmdline;
2125 seed = (unsigned int)l;
2128 str = strtok_r( NULL, str_delimiters, lasts );
2129 if ( ! str || ! strcmp( str, "." ) ) { str = "localhost"; }
2130 strncpy( client_str_addr, str, 255 );
2131 client_str_addr[255] = '\0';
2134 str = strtok_r( NULL, str_delimiters, lasts );
2135 if ( ! str || ! strcmp( str, "." ) ) { str = "4082"; }
2136 l = strtol( str, &ptr, 0 );
2137 if ( ptr == str || l == LONG_MAX || l < 0 || l > USHRT_MAX )
2139 str_error = str_bad_cmdline;
2142 client_port = (int)l;
2145 str = strtok_r( NULL, str_delimiters, lasts );
2146 if ( ! str || ! strcmp( str, "." ) ) { str = "bonanza1"; }
2147 strncpy( client_str_id, str, 255 );
2148 client_str_id[255] = '\0';
2150 str = strtok_r( NULL, str_delimiters, lasts );
2151 if ( ! str || ! strcmp( str, "." ) ) { str = "1.0"; }
2152 factor = strtod( str, &ptr );
2153 if ( ptr == str || factor < 0.0 )
2155 str_error = str_bad_cmdline;
2159 str = strtok_r( NULL, str_delimiters, lasts );
2160 if ( ! str || ! strcmp( str, "." ) ) { l = -1; }
2162 l = strtol( str, &ptr, 0 );
2163 if ( ptr == str || l == LONG_MAX )
2165 str_error = str_bad_cmdline;
2169 if ( l <= 0 ) { mnj_depth_stable = INT_MAX; }
2170 else { mnj_depth_stable = (int)l; }
2172 AbortDifficultCommand;
2174 resign_threshold = 65535;
2175 game_status |= ( flag_noponder | flag_noprompt );
2176 if ( mnj_reset_tbl( sd, seed ) < 0 ) { return -1; }
2178 sckt_mnj = sckt_connect( client_str_addr, (int)client_port );
2179 if ( sckt_mnj == SCKT_NULL ) { return -2; }
2181 str_buffer_cmdline[0] = '\0';
2183 Out( "Sending my name %s", client_str_id );
2184 MnjOut( "%s %g final%s\n", client_str_id, factor,
2185 ( mnj_depth_stable == INT_MAX ) ? "" : " stable" );
2187 return cmd_suspend();