Example #1
0
void cmd_pgnload(void)
{
  char tmp_epd[]=".tmp.epd";
  char data[MAXSTR]="";
  FILE *epdfile=NULL;
  char epdline[MAXSTR]="";

  PGNReadFromFile (token[1],0);
  SaveEPD( tmp_epd );
  epdfile = fopen( tmp_epd, "r" );
  if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
    printf( _("Incorrect epd file\n") );
    return;
  }
  strcpy( data, "setboard " );
  int i=0;
  while ( epdline[i] != '\n' ) {
    data[i+9] = epdline[i];
    ++i;
  }
  data[i+9] = '\0';
  SetDataToEngine( data );
  SetAutoGo( true );
  pgnloaded = 0;
}
Example #2
0
void cmd_load(void)
{
  char data[MAXSTR]="";
  LoadEPD (token[1]);
  pgnloaded = 0;
  check_board();
  if (!ValidateBoard()) {
    SET (flags, ENDED);
    printf (_("Board is wrong!\n"));
  } else {
    /* Read EPD file and send contents to engine */
    FILE *epdfile = fopen( token[1], "r" );
    char epdline[MAXSTR]="";
    if ( epdfile == NULL ) {
      printf(_("Error reading file '%s'\n"), token[1] );
    } else {
      if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
        printf(_("Error reading file '%s'\n"), token[1] );
      } else {
        strcpy( data, "setboard " );
        int i=0;
        while ( epdline[i] != '\n' ) {
          data[i+9] = epdline[i];
          ++i;
        }
        data[i+9] = '\0';
        SetDataToEngine( data );
        SetAutoGo( true );
      }
    }
  }
}
Example #3
0
void cmd_pgnreplay(void)
{
  char tmp_epd[]=".tmp.epd";
  char data[MAXSTR]="";
  FILE *epdfile=NULL;
  char epdline[MAXSTR]="";

  PGNReadFromFile (token[1],1);

  SaveEPD( tmp_epd );
  epdfile = fopen( tmp_epd, "r" );
  if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
    printf( _("Incorrect epd file\n") );
    return;
  }

  strcpy( data, "setboard " );
  int i=0;
  while ( epdline[i] != '\n' ) {
    data[i+9] = epdline[i];
    ++i;
  }
  data[i+9] = '\0';

  SetDataToEngine( data );
  SetAutoGo( true );

  pgnloaded = 1;
  pgncnt = GameCnt;

  while (GameCnt >= 0) {
    if (GameCnt >= 0) {
      CLEAR (flags, ENDED);
      CLEAR (flags, TIMEOUT);
      ChangeColor( true );
      SetAutoGo( true );
      UnmakeMove (board.side, &Game[GameCnt].move);
      if (GameCnt >= 0) {
        UnmakeMove (board.side, &Game[GameCnt].move);
      }
    }
  }

  cmd_first();
}
Example #4
0
void cmd_last(void)
{
  if (!pgnloaded)
    return;

  while (GameCnt+1 <= pgncnt) {
    ChangeColor( true );
    SetAutoGo( true );
    MakeMove (board.side, &Game[GameCnt+1].move);
  }

  printf("%d. ",GameCnt/2+1);
  printf("%s\n", Game[GameCnt].SANmv);
  ShowBoard ();
}
Example #5
0
void cmd_next(void)
{
  if (!pgnloaded)
    return;

  if ((GameCnt+1) <= pgncnt) {
    ChangeColor( true );
    SetAutoGo( true );
    MakeMove (board.side, &Game[GameCnt+1].move);
  } else {
    printf(_("No more moves. Game reached the end.\n"));
    return;
  }

  printf("%d. ",GameCnt/2+1);
  printf("%s\n", Game[GameCnt].SANmv);
  ShowBoard ();
}
Example #6
0
void cmd_previous(void)
{
  if (!pgnloaded)
    return;

  if (GameCnt >= 0) {
    ChangeColor( true );
    SetAutoGo( true );
    UnmakeMove (board.side, &Game[GameCnt].move);
  }
  else {
    printf(_("Initial position reached. There are no earlier moves.\n"));
    return;
  }

  printf("%d. ",GameCnt/2+1);
  printf("%s\n", Game[GameCnt].SANmv);
  ShowBoard ();
}
Example #7
0
void cmd_first(void)
{
  if (!pgnloaded)
    return;

  while (GameCnt >= 0) {
    if (GameCnt >= 0) {
      CLEAR (flags, ENDED);
      CLEAR (flags, TIMEOUT);
      ChangeColor( true );
      SetAutoGo( true );
      UnmakeMove (board.side, &Game[GameCnt].move);
      if (GameCnt >= 0) {
        UnmakeMove (board.side, &Game[GameCnt].move);
      }
    }
  }

  ShowBoard ();
}
Example #8
0
File: engine.c Project: adua/chess
/*
 * Extracts a command from the user input buffer.
 * 
 * The command is removed from the buffer.
 * If the command must be sent to the engine, it is sent.
 * This function relies on parse_input().
 */
void NextUserCmd( void )
{
  char userinput[BUF_SIZE]="";
  
  if ( strlen( userinputbuf ) > 0 ) {
    printf("TimeLimit[0] = %g\n", TimeLimit[0]);
    printf("TimeLimit[1] = %g\n", TimeLimit[1]);
    if ( flags & XBOARD ) {
      fflush( stdout );
    }
    if ( GetNextLine( userinputbuf, userinput ) > 0 ) {
      strcpy( inputstr, "" );
      strcpy( inputstr, userinput );
      dbg_printf( "USER >: %s\n", userinput );
      parse_input();
      /* Check if command/move must be sent to engine */
      if ( GetDataToEngine( dataToEngine ) ) {
        dbg_printf( "> ENGINE: %s\n", dataToEngine );
        SendToEngine( dataToEngine );
        if ( GetAutoGo() && UserInputIsAValidMove() ) {
            strcpy( userinputbuf, "go\n" );
            SetAutoGo( false );
        }
      }
      showprompt = !AnswerFromEngineExpected();
      /* Check if command was entered in manual mode */
      if ( (flags & MANUAL) && UserInputIsAValidMove() ) {
        RealGameCnt = GameCnt;
        RealSide = board.side;
        showprompt = 1;
      }
      /* Check if the color must be changed, e.g. after an undo command. */
      if ( changeColor ) {
        RealGameCnt = GameCnt;
        RealSide = board.side;
      }
    }
  } 
}