"Fossies" - the Fresh Open Source Software Archive  

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

About: GNU Chess is a chess-playing program.

engine.cc  (gnuchess-6.2.4):engine.cc  (gnuchess-6.2.5)
skipping to change at line 55 skipping to change at line 55
/* Message to be sent to the engine */ /* Message to be sent to the engine */
char dataToEngine[BUF_SIZE]=""; char dataToEngine[BUF_SIZE]="";
/* Whether an answer is expected from the engine or not, as a result of a comman d send to it. */ /* Whether an answer is expected from the engine or not, as a result of a comman d send to it. */
static int answerFromEngineExpected=false; static int answerFromEngineExpected=false;
/* A BUF_SIZE long char string made up of null characters */ /* A BUF_SIZE long char string made up of null characters */
static char zerochar[BUF_SIZE]; static char zerochar[BUF_SIZE];
/* Whether the prompt must be displayed or not. */
static int showprompt=1;
/* Buffer storing the input entered by the user */ /* Buffer storing the input entered by the user */
char userinputbuf[BUF_SIZE]=""; char userinputbuf[BUF_SIZE]="";
/* Buffer storing the input coming from the engine */ /* Buffer storing the input coming from the engine */
static char engineinputbuf[BUF_SIZE]=""; static char engineinputbuf[BUF_SIZE]="";
/* Whether the input is a move or not (if not, it is expected to be a command). */ /* Whether the input is a move or not (if not, it is expected to be a command). */
static int userInputIsAMove=0; static int userInputIsAMove=0;
/* Flags that the color must be changed */ /* Flags that the color must be changed */
skipping to change at line 82 skipping to change at line 79
/* /*
* Forward declaration of functions * Forward declaration of functions
*/ */
int SendToEngine( char msg[] ); int SendToEngine( char msg[] );
static int GetNextLine( char buf[], char line[] ); static int GetNextLine( char buf[], char line[] );
static int GetDataToEngine( char data[] ); static int GetDataToEngine( char data[] );
static int AnswerFromEngineExpected( void ); static int AnswerFromEngineExpected( void );
static int UserInputIsAValidMove( void ); static int UserInputIsAValidMove( void );
void InitInputThread(void);
void input_wakeup( void );
/* /*
* Initializes data used in the frontend. * Initializes data used in the frontend.
*/ */
void InitFrontend( void ) void InitFrontend( void )
{ {
/* Initialized a null char string that will be used later on. */ /* Initialized a null char string that will be used later on. */
int i; int i;
for ( i=0; i<BUF_SIZE; ++i ) for ( i=0; i<BUF_SIZE; ++i )
zerochar[i] = '\0'; zerochar[i] = '\0';
InitInput();
InitInputThread();
} }
/* /*
* Sends a char string message from the frontend to the adapter/engine. * Sends a char string message from the frontend to the adapter/engine.
* The message must be a command or a move. * The message must be a command or a move.
*/ */
int SendToEngine( char msg[] ) int SendToEngine( char msg[] )
{ {
int outError=0; int outError=0;
int msg_size = strlen( msg ); int msg_size = strlen( msg );
skipping to change at line 177 skipping to change at line 178
void ReadFromUser( void ) void ReadFromUser( void )
{ {
int nread=0; int nread=0;
fd_set set[1]; fd_set set[1];
struct timeval time_val[1]; struct timeval time_val[1];
int userinputready=0; int userinputready=0;
char userinputaux[BUF_SIZE]=""; char userinputaux[BUF_SIZE]="";
/* Poll input from user in non-blocking mode */ /* Poll input from user in non-blocking mode */
FD_ZERO(set); FD_ZERO(set);
FD_SET(STDIN_FILENO,set); FD_SET(pipefd_i2f[0],set);
time_val->tv_sec = 0; time_val->tv_sec = 0;
time_val->tv_usec = 0; time_val->tv_usec = 0;
userinputready = select( STDIN_FILENO+1, set, NULL, NULL, time_val ); userinputready = select( pipefd_i2f[0]+1, set, NULL, NULL, time_val );
if ( userinputready == -1 ) { if ( userinputready == -1 ) {
printf( "Error reading user input.\n" ); printf( "Error reading user input.\n" );
} else if ( userinputready > 0 ) { } else if ( userinputready > 0 ) {
/* There are some data from the user. Store it in buffer */ /* There are some data from the user. Store it in buffer */
strncpy( userinputaux, zerochar, BUF_SIZE ); strncpy( userinputaux, zerochar, BUF_SIZE );
nread = read( STDIN_FILENO, userinputaux, BUF_SIZE ); nread = read( pipefd_i2f[0], userinputaux, BUF_SIZE );
strcat( userinputbuf, userinputaux ); strcat( userinputbuf, userinputaux );
userinputbuf[strlen( userinputbuf ) + nread] = '\0'; userinputbuf[strlen( userinputbuf ) + nread] = '\0';
} }
} }
/* /*
* Saves in global variable 'dataToEngine' the data to be sent to the engine. * Saves in global variable 'dataToEngine' the data to be sent to the engine.
*/ */
void SetDataToEngine( const char data[] ) void SetDataToEngine( const char data[] )
{ {
skipping to change at line 239 skipping to change at line 240
* Return value: * Return value:
* 1 - an answer is expected from the engine * 1 - an answer is expected from the engine
* 0 - an answer is not expected from the engine * 0 - an answer is not expected from the engine
*/ */
static int AnswerFromEngineExpected( void ) static int AnswerFromEngineExpected( void )
{ {
return ( answerFromEngineExpected ); return ( answerFromEngineExpected );
} }
/* /*
* If the prompt must be displayed on the standard output, according to
* the current state, it is displayed.
*/
void ShowPrompt( void )
{
char prompt[MAXSTR] = "";
if ( showprompt && !(flags & XBOARD) ) {
sprintf(prompt,"%s (%d) : ",
RealSide ? _("Black") : _("White"),
(RealGameCnt+1)/2 + 1 );
fprintf( stdout, "%s", prompt );
fflush( stdout );
showprompt = 0;
}
}
/*
* Extracts a command from the user input buffer. * Extracts a command from the user input buffer.
* *
* The command is removed from the buffer. * The command is removed from the buffer.
* If the command must be sent to the engine, it is sent. * If the command must be sent to the engine, it is sent.
* This function relies on parse_input(). * This function relies on parse_input().
*/ */
void NextUserCmd( void ) void NextUserCmd( void )
{ {
char userinput[BUF_SIZE]=""; char userinput[BUF_SIZE]="";
if ( strlen( userinputbuf ) > 0 ) { if ( strlen( userinputbuf ) > 0 ) {
printf("TimeLimit[0] = %g\n", TimeLimit[0]);
printf("TimeLimit[1] = %g\n", TimeLimit[1]);
if ( flags & XBOARD ) { if ( flags & XBOARD ) {
fflush( stdout ); fflush( stdout );
} }
if ( GetNextLine( userinputbuf, userinput ) > 0 ) { if ( GetNextLine( userinputbuf, userinput ) > 0 ) {
strcpy( inputstr, "" ); strcpy( inputstr, "" );
strcpy( inputstr, userinput ); strcpy( inputstr, userinput );
dbg_printf( "USER >: %s\n", userinput ); dbg_printf( "USER >: %s\n", userinput );
parse_input(); parse_input();
/* Check if command/move must be sent to engine */ /* Check if command/move must be sent to engine */
if ( GetDataToEngine( dataToEngine ) ) { if ( GetDataToEngine( dataToEngine ) ) {
dbg_printf( "> ENGINE: %s\n", dataToEngine ); dbg_printf( "> ENGINE: %s\n", dataToEngine );
SendToEngine( dataToEngine ); SendToEngine( dataToEngine );
if ( GetAutoGo() && UserInputIsAValidMove() ) { if ( GetAutoGo() && UserInputIsAValidMove() ) {
strcpy( userinputbuf, "go\n" ); strcpy( userinputbuf, "go\n" );
SetAutoGo( false ); SetAutoGo( false );
} }
} }
showprompt = !AnswerFromEngineExpected();
/* Check if command was entered in manual mode */ /* Check if command was entered in manual mode */
if ( (flags & MANUAL) && UserInputIsAValidMove() ) { if ( (flags & MANUAL) && UserInputIsAValidMove() ) {
RealGameCnt = GameCnt; RealGameCnt = GameCnt;
RealSide = board.side; RealSide = board.side;
showprompt = 1;
} }
/* Check if the color must be changed, e.g. after an undo command. */ /* Check if the color must be changed, e.g. after an undo command. */
if ( changeColor ) { if ( changeColor ) {
RealGameCnt = GameCnt; RealGameCnt = GameCnt;
RealSide = board.side; RealSide = board.side;
} }
if ( !AnswerFromEngineExpected() || (flags & MANUAL) ) {
input_wakeup();
}
} }
} }
} }
/* /*
* Extracts a command from the engine input buffer. * Extracts a command from the engine input buffer.
* *
* The command is removed from the buffer. * The command is removed from the buffer.
* If the command is a move, the move is made. * If the command is a move, the move is made.
*/ */
skipping to change at line 344 skipping to change at line 327
fflush( stdout ); fflush( stdout );
} else { } else {
dbg_printf("USER <: %d. ... %s\n", GameCnt/2 + 1, enginemovest r ); dbg_printf("USER <: %d. ... %s\n", GameCnt/2 + 1, enginemovest r );
printf ("%d. ... %s\n", GameCnt/2 + 1, enginemovestr ); printf ("%d. ... %s\n", GameCnt/2 + 1, enginemovestr );
fflush( stdout ); fflush( stdout );
dbg_printf("USER <: My move is : %s\n", enginemovestr); dbg_printf("USER <: My move is : %s\n", enginemovestr);
printf( "My move is : %s\n", enginemovestr ); printf( "My move is : %s\n", enginemovestr );
fflush( stdout ); fflush( stdout );
} }
RealGameCnt = GameCnt; RealGameCnt = GameCnt;
showprompt = 1;
/* Check if the color must be changed, e.g. after a go command. */ /* Check if the color must be changed, e.g. after a go command. */
if ( changeColor ) { if ( changeColor ) {
RealGameCnt = GameCnt; RealGameCnt = GameCnt;
RealSide = board.side; RealSide = board.side;
} }
input_wakeup();
} }
} else { } else {
dbg_printf( "USER <: %s\n",engineinput ); dbg_printf( "USER <: %s\n",engineinput );
printf( "%s", engineinput ); printf( "%s", engineinput );
if ( flags & XBOARD ) { if ( flags & XBOARD ) {
fflush( stdout ); fflush( stdout );
} }
if ( AnswerFromEngineExpected() ) {
input_wakeup();
}
} }
} }
} }
} }
/* /*
* Stores in a global flag variable whether an input from the user is a * Stores in a global flag variable whether an input from the user is a
* valid move (1) or not (0). * valid move (1) or not (0).
*/ */
void SetUserInputValidMove( int valid ) void SetUserInputValidMove( int valid )
 End of changes. 14 change blocks. 
28 lines changed or deleted 14 lines changed or added

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