"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/frontend/cmd.cc" between
gnuchess-6.2.5.tar.gz and gnuchess-6.2.6.tar.gz

About: GNU Chess is a chess-playing program.

cmd.cc  (gnuchess-6.2.5):cmd.cc  (gnuchess-6.2.6)
/* cmd.c /* cmd.cc
GNU Chess frontend GNU Chess frontend
Copyright (C) 2001-2013 Free Software Foundation, Inc. Copyright (C) 2001-2020 Free Software Foundation, Inc.
GNU Chess is based on the two research programs GNU Chess is based on the two research programs
Cobalt by Chua Kong-Sian and Gazebo by Stuart Cracraft. Cobalt by Chua Kong-Sian and Gazebo by Stuart Cracraft.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
skipping to change at line 147 skipping to change at line 147
strcpy( data, "book " ); strcpy( data, "book " );
if (tokeneq(token[1], "add")) { if (tokeneq(token[1], "add")) {
if (access(token[2], F_OK) < 0) { if (access(token[2], F_OK) < 0) {
printf(_("The syntax to add a new book is:\n\n\tbook add file.pgn\n")); printf(_("The syntax to add a new book is:\n\n\tbook add file.pgn\n"));
} else { } else {
strcat( data, "add " ); strcat( data, "add " );
strcat( data, token[2] ); strcat( data, token[2] );
} }
} else if (tokeneq (token[1], "on") || tokeneq(token[1], "prefer")) { } else if (tokeneq (token[1], "on") || tokeneq(token[1], "prefer")) {
strcpy( data, "book on" ); strcpy( data, "book on" );
printf(_("book is now on\n")); printf(_("Book is now on.\n"));
} else if (tokeneq (token[1], "off")) { } else if (tokeneq (token[1], "off")) {
strcpy( data, "book off" ); strcpy( data, "book off" );
printf(_("book is now off\n")); printf(_("Book is now off.\n"));
} else if (tokeneq (token[1], "best")) { } else if (tokeneq (token[1], "best")) {
strcpy( data, "book best" ); strcpy( data, "book best" );
printf(_("book is now best\n")); printf(_("Book is now best.\n"));
} else if (tokeneq (token[1], "worst")) { } else if (tokeneq (token[1], "worst")) {
strcpy( data, "book worst" ); strcpy( data, "book worst" );
printf(_("book is now worst\n")); printf(_("Book is now worst.\n"));
} else if (tokeneq (token[1], "random")) { } else if (tokeneq (token[1], "random")) {
strcpy( data, "book random" ); strcpy( data, "book random" );
printf(_("book is now random\n")); printf(_("Book is now random.\n"));
} else { } else {
printf( _("Incorrect book option\n") ); printf( _("Incorrect book option: '%s'.\n"), token[1] );
return; return;
} }
SetDataToEngine( data ); SetDataToEngine( data );
} }
void cmd_depth(void) void cmd_depth(void)
{ {
char data[MAXSTR]=""; char data[MAXSTR]="";
int searchDepth=0; int searchDepth=0;
searchDepth = atoi( token[1] ); searchDepth = atoi( token[1] );
sprintf( data, "sd %d", searchDepth ); sprintf( data, "sd %d", searchDepth );
SetDataToEngine( data ); SetDataToEngine( data );
printf(_("Search to a depth of %d\n"),searchDepth); printf(_("Search to a depth of %d.\n"),searchDepth);
} }
void cmd_easy(void) void cmd_easy(void)
{ {
SetDataToEngine( token[0] ); SetDataToEngine( token[0] );
} }
/* Predecessor to setboard */ /* Predecessor to setboard */
void cmd_edit(void) void cmd_edit(void)
{ {
skipping to change at line 269 skipping to change at line 269
void cmd_level(void) void cmd_level(void)
{ {
SetDataToEngine( token[0] ); SetDataToEngine( token[0] );
sscanf (token[1], "%d %f %d", &TCMove, &TCTime, &TCinc); sscanf (token[1], "%d %f %d", &TCMove, &TCTime, &TCinc);
if (TCMove == 0) { if (TCMove == 0) {
TCMove = 35 /* MIN((5*(GameCnt+1)/2)+1,60) */; TCMove = 35 /* MIN((5*(GameCnt+1)/2)+1,60) */;
printf("TCMove = %d\n",TCMove); printf("TCMove = %d\n",TCMove);
} }
if (TCTime == 0) { if (TCTime == 0) {
SearchTime = TCinc / 2.0f ; SearchTime = TCinc / 2.0f ;
printf(_("Fischer increment of %d seconds\n"),TCinc); printf(_("Fischer increment of %d seconds.\n"),TCinc);
} else { } else {
MoveLimit[white] = MoveLimit[black] = TCMove - (GameCnt+1)/2; MoveLimit[white] = MoveLimit[black] = TCMove - (GameCnt+1)/2;
TimeLimit[white] = TimeLimit[black] = TCTime * 60; TimeLimit[white] = TimeLimit[black] = TCTime * 60;
if (!(flags & XBOARD)) { if (!(flags & XBOARD)) {
/* TRANSLATORS: Please be aware that the word 'move' is sometimes /* TRANSLATORS: Please be aware that the word 'move' is sometimes
used as a synonym of 'ply', and sometimes in the sense of a used as a synonym of 'ply', and sometimes in the sense of a
full 2-ply move. */ full 2-ply move. */
printf (_("Time Control: %d moves in %.2f secs\n"), printf (_("Time control: %d moves in %.2f secs.\n"),
MoveLimit[white], TimeLimit[white]); MoveLimit[white], TimeLimit[white]);
printf(_("Fischer increment of %d seconds\n"),TCinc); printf(_("Fischer increment of %d seconds.\n"),TCinc);
} }
} }
} }
void cmd_list(void) void cmd_list(void)
{ {
if (token[1][0] == '?') { if (token[1][0] == '?') {
printf(_("name - list known players alphabetically\n")); printf(_("name - list known players alphabetically\n"));
printf(_("score - list by GNU best result first \n")); printf(_("score - list by GNU best result first\n"));
printf(_("reverse - list by GNU worst result first\n")); printf(_("reverse - list by GNU worst result first\n"));
} else { } else {
if (token[1][0] == '\0') DBListPlayer("rscore"); if (token[1][0] == '\0') DBListPlayer("rscore");
else DBListPlayer(token[1]); else DBListPlayer(token[1]);
} }
} }
void cmd_load(void) void cmd_load(void)
{ {
char data[MAXSTR]=""; char data[MAXSTR]="";
skipping to change at line 310 skipping to change at line 310
pgnloaded = 0; pgnloaded = 0;
check_board(); check_board();
if (!ValidateBoard()) { if (!ValidateBoard()) {
SET (flags, ENDED); SET (flags, ENDED);
printf (_("Board is wrong!\n")); printf (_("Board is wrong!\n"));
} else { } else {
/* Read EPD file and send contents to engine */ /* Read EPD file and send contents to engine */
FILE *epdfile = fopen( token[1], "r" ); FILE *epdfile = fopen( token[1], "r" );
char epdline[MAXSTR]=""; char epdline[MAXSTR]="";
if ( epdfile == NULL ) { if ( epdfile == NULL ) {
printf(_("Error reading file '%s'\n"), token[1] ); printf(_("Error reading file '%s'.\n"), token[1] );
} else { } else {
if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) { if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
printf(_("Error reading file '%s'\n"), token[1] ); printf(_("Error reading file '%s'.\n"), token[1] );
} else { } else {
strcpy( data, "setboard " ); const char setboardCmd[] = "setboard ";
unsigned int setboardLen = strlen(setboardCmd);
strcpy( data, setboardCmd );
int i=0; int i=0;
while ( epdline[i] != '\n' ) { while ( epdline[i] != '\n' ) {
data[i+9] = epdline[i]; if (i + setboardLen < MAXSTR - 1) {
++i; data[i+setboardLen] = epdline[i];
++i;
} else {
printf(_("Error reading contents of file '%s'.\n"), token[1] );
break;
}
} }
data[i+9] = '\0'; data[i+setboardLen] = '\0';
SetDataToEngine( data ); SetDataToEngine( data );
SetAutoGo( true ); SetAutoGo( true );
} }
} }
} }
} }
void cmd_manual(void) void cmd_manual(void)
{ {
SET (flags, MANUAL); SET (flags, MANUAL);
skipping to change at line 443 skipping to change at line 450
{ {
char tmp_epd[]=".tmp.epd"; char tmp_epd[]=".tmp.epd";
char data[MAXSTR]=""; char data[MAXSTR]="";
FILE *epdfile=NULL; FILE *epdfile=NULL;
char epdline[MAXSTR]=""; char epdline[MAXSTR]="";
PGNReadFromFile (token[1],0); PGNReadFromFile (token[1],0);
SaveEPD( tmp_epd ); SaveEPD( tmp_epd );
epdfile = fopen( tmp_epd, "r" ); epdfile = fopen( tmp_epd, "r" );
if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) { if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
printf( _("Incorrect epd file\n") ); printf( _("Incorrect epd file.\n") );
return; return;
} }
strcpy( data, "setboard " ); strcpy( data, "setboard " );
int i=0; int i=0;
while ( epdline[i] != '\n' ) { while ( epdline[i] != '\n' ) {
data[i+9] = epdline[i]; data[i+9] = epdline[i];
++i; ++i;
} }
data[i+9] = '\0'; data[i+9] = '\0';
SetDataToEngine( data ); SetDataToEngine( data );
skipping to change at line 470 skipping to change at line 477
char tmp_epd[]=".tmp.epd"; char tmp_epd[]=".tmp.epd";
char data[MAXSTR]=""; char data[MAXSTR]="";
FILE *epdfile=NULL; FILE *epdfile=NULL;
char epdline[MAXSTR]=""; char epdline[MAXSTR]="";
PGNReadFromFile (token[1],1); PGNReadFromFile (token[1],1);
SaveEPD( tmp_epd ); SaveEPD( tmp_epd );
epdfile = fopen( tmp_epd, "r" ); epdfile = fopen( tmp_epd, "r" );
if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) { if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
printf( _("Incorrect epd file\n") ); printf( _("Incorrect epd file.\n") );
return; return;
} }
strcpy( data, "setboard " ); strcpy( data, "setboard " );
int i=0; int i=0;
while ( epdline[i] != '\n' ) { while ( epdline[i] != '\n' ) {
data[i+9] = epdline[i]; data[i+9] = epdline[i];
++i; ++i;
} }
data[i+9] = '\0'; data[i+9] = '\0';
skipping to change at line 773 skipping to change at line 780
TimeLimit[board.side] += Game[GameCnt+1].et; TimeLimit[board.side] += Game[GameCnt+1].et;
if (!(flags & XBOARD)) ShowBoard (); if (!(flags & XBOARD)) ShowBoard ();
} }
void cmd_usage(void) void cmd_usage(void)
{ {
printf ( "\n" ); printf ( "\n" );
printf ( _("\ printf ( _("\
Usage: %s [OPTION]...\n\n"), progname ); Usage: %s [OPTION]...\n\n"), progname );
fputs( _("\ fputs( _("\
Play the game of chess\n\n"), stdout ); Play the game of chess.\n\n"), stdout );
fputs( _("Options:\n"), stdout ); fputs( _("Options:\n"), stdout );
fputs( _("\ fputs( _("\
-h, --help display this help and exit\n"), stdout ); -h, --help display this help and exit\n"), stdout );
fputs( _("\ fputs( _("\
-v, --version display version information and exit\n"), stdout ); -v, --version display version information and exit\n"), stdout );
fputs( _("\ fputs( _("\
-q, --quiet make the program silent on startup\n"), stdout ); -q, --quiet make the program silent on startup\n"), stdout );
fputs( _("\ fputs( _("\
--silent same as -q\n"), stdout ); --silent same as -q\n"), stdout );
fputs( _("\ fputs( _("\
skipping to change at line 1128 skipping to change at line 1135
gettext_noop(" evalspeed - tests speed of the evaluator"), gettext_noop(" evalspeed - tests speed of the evaluator"),
"bk", "bk",
gettext_noop(" Shows moves from opening book."), gettext_noop(" Shows moves from opening book."),
"graphic", "graphic",
gettext_noop(" Enables display board in graphic mode."), gettext_noop(" Enables display board in graphic mode."),
"nographic", "nographic",
gettext_noop(" Disables graphic mode and display classical view."), gettext_noop(" Disables graphic mode and display classical view."),
"coords", "coords",
gettext_noop(" Displays the chessboard rank and file in both graphic and clas sical views."), gettext_noop(" Displays the chessboard rank and file in both graphic and clas sical views."),
"nocoords", "nocoords",
gettext_noop(" Does not display the chessboard rank nor file in either mode ( graphic nor classical)"), gettext_noop(" Does not display the chessboard rank nor file in either mode ( graphic nor classical)."),
NULL, NULL,
NULL NULL
}; };
void cmd_help (void) void cmd_help (void)
/************************************************************************** /**************************************************************************
* *
* Display all the help commands. * Display all the help commands.
* *
**************************************************************************/ **************************************************************************/
skipping to change at line 1154 skipping to change at line 1161
for (p=helpstr, count=0; *p; p++) { for (p=helpstr, count=0; *p; p++) {
if (strncmp(*p, token[1], strlen(token[1])) == 0) { if (strncmp(*p, token[1], strlen(token[1])) == 0) {
puts(*p); puts(*p);
while (*++p && **p != ' ') /* Skip aliases */ ; while (*++p && **p != ' ') /* Skip aliases */ ;
for (; *p && **p == ' '; p++) { for (; *p && **p == ' '; p++) {
puts(_(*p)); puts(_(*p));
} }
return; return;
} }
} }
printf(_("Help for command %s not found\n\n"), token[1]); printf(_("Help for command '%s' not found.\n\n"), token[1]);
} }
printf(_("List of commands: (help COMMAND to get more help)\n")); printf(_("List of commands: (help COMMAND to get more help)\n"));
for (p=helpstr, count=0; *p; p++) { for (p=helpstr, count=0; *p; p++) {
len = strcspn(*p, " "); len = strcspn(*p, " ");
if (len > 0) { if (len > 0) {
count += printf("%.*s ", len, *p); count += printf("%.*s ", len, *p);
if (count > 60) { if (count > 60) {
count = 0; count = 0;
puts(""); puts("");
} }
skipping to change at line 1284 skipping to change at line 1291
split_input(); split_input();
for (meth = commands; meth->name != NULL; meth++) { for (meth = commands; meth->name != NULL; meth++) {
if (tokeneq(token[0], meth->name)) { if (tokeneq(token[0], meth->name)) {
meth->method(); meth->method();
return; return;
} }
} }
/* OK, no known command, this should be a move */ /* OK, no known command, this should be a move */
ptr = ValidateMove (token[0]); char cleanMove[MAXSTR]="";
ptr = ValidateMove (token[0], cleanMove);
if (ptr != NULL) { if (ptr != NULL) {
/* Since the user entered a move: /* Since the user entered a move:
* 1. The move must be sent to the engine. * 1. The move must be sent to the engine.
* 2. A reply is expected from the engine. * 2. A reply is expected from the engine.
*/ */
SetUserInputValidMove( 1 ); SetUserInputValidMove( 1 );
SetDataToEngine( token[0] ); SetDataToEngine( cleanMove );
pgnloaded = 0; pgnloaded = 0;
ExpectAnswerFromEngine( true ); ExpectAnswerFromEngine( true );
SANMove (ptr->move, 1); SANMove (ptr->move, 1);
MakeMove (board.side, &ptr->move); MakeMove (board.side, &ptr->move);
strcpy (Game[GameCnt].SANmv, SANmv); strcpy (Game[GameCnt].SANmv, SANmv);
printf("%d. ",GameCnt/2+1); printf("%d. ",GameCnt/2+1);
printf("%s",token[0]); printf("%s",token[0]);
if (ofp != stdout) { if (ofp != stdout) {
fprintf(ofp,"%d. ",GameCnt/2+1); fprintf(ofp,"%d. ",GameCnt/2+1);
fprintf(ofp,"%s",token[0]); fprintf(ofp,"%s",token[0]);
 End of changes. 25 change blocks. 
26 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)