Ejemplo n.º 1
0
Chess::Chess(char FEN[])
{
    init_bitboard();

    memset(moves, 0, STORE_SIZE);
    clearPosition(&pos);

    loadPositionFromFEN(FEN, &pos);

}
Ejemplo n.º 2
0
void
global_setup( int use_random, int hash_bits ) {
  FILE *log_file;
  time_t timer;

  /* Clear the log file. No error handling done. */

#if defined(ANDROID)
  sprintf(log_file_path, "%s/%s", android_files_dir, LOG_FILE_NAME);
#elif defined(__linux__)
  strcpy( log_file_path, LOG_FILE_NAME );
#else
  char directory_buffer[MAX_PATH_LENGTH];
  getcwd( directory_buffer, MAX_PATH_LENGTH );
  if ( directory_buffer[strlen( directory_buffer ) - 1] == '\\' )
    sprintf( log_file_path, "%s%s", directory_buffer, LOG_FILE_NAME );
  else
    sprintf( log_file_path, "%s\\%s", directory_buffer, LOG_FILE_NAME );
#endif

  if ( use_log_file ) {
    log_file = fopen( log_file_path, "w" );
    if ( log_file != NULL ) {
      time( &timer );
      fprintf( log_file, "%s %s\n", LOG_TEXT, ctime( &timer ) );
      fprintf( log_file, "%s %s %s\n", ENGINE_TEXT, __DATE__, __TIME__ );
      fclose( log_file );
    }
  }

  if ( use_random ) {
    time( &timer );
    my_srandom( timer );
  }
  else
    my_srandom( 1 );

  init_hash( hash_bits );
  init_bitboard();
  init_moves();
  init_patterns();
  init_coeffs();
  init_timer();
  init_probcut();
  init_stable();
  setup_search();
}
Ejemplo n.º 3
0
int
main(void)
{
    struct ai_state ai_state;
    struct bitboard board;
    enum color cur_player;
    struct move move;

    enum result result;
    int gameover = 1;

    static char buf[4096];
    char *p;

    seed_ai(&ai_state);

    while (1) {
        if (gameover) {
            init_bitboard(&board);
            cur_player = WHITE;
            gameover = 0;
        }

        print_bitboard(&board, cur_player);

        printf("%s>%s ", cur_player == WHITE ? "\033[1;36m" : "\033[0;35m",
                "\033[0m");
        fflush(stdout);

        fread_until((unsigned char *)buf, '\n', sizeof(buf), stdin);
        if ((p = strchr(buf, '\n')) != NULL)
            *p = '\0';
        else
            continue;

        if (strcmp(buf, "quit") == 0)
            break;

        if (parse_san(&board, cur_player, buf, &move) != 0 ||
                (result = make_move(&board, &move)) == ERROR) {
            printf("INVALID MOVE!\n");
            continue;
        }

#ifdef PATCHED_1
        printf("\n%s\n%x\n", buf, calculate_csum(result));
#else
        printf("\n");
        printf(buf);
        printf("\n%x\n", calculate_csum(result));
#endif

        switch (result) {
        case CHECK:
            printf("CHECK!\n");
            break;
        case CHECKMATE:
            printf("CHECKMATE!\n");
            gameover = 1;
            break;
        case STALEMATE:
            printf("STALEMATE!\n");
            gameover = 1;
            break;
        case CONTINUE:
        default:
            break;
        }

        cur_player = (cur_player == WHITE ? BLACK : WHITE);
    }

    return 0;
}