void use_square_ok1() { int i; square_init(2, i); // OK since i is initialized when passed by reference }
TEngine::TEngine(AnsiString FileName) { util_init(); my_random_init(); square_init(); piece_init(); pawn_init_bit(); value_init(); vector_init(); attack_init(); move_do_init(); random_init(); hash_init(); Reversed = true; board_from_fen(&StartBoard,StartFen); board_from_fen(&Board,StartFen); GameStarted = false; StateNewGame = false; LastCommitMove[0] = 0; Process = new TProcess(FileName); Process->Send("uci"); char buf[10000]; do { Sleep(10); if (Process->Get(buf)) { char *next_line = buf; while (true) { char *cur_line = next_line; if (cur_line[0] == 0) break; char *end = strstr(cur_line,"\r\n"); end[0] = 0; end[1] = 0; next_line = end + 2; char *cur_word; while (cur_line) { cur_word = get_cur_word_str(&cur_line); int pos; if (string_equal(cur_word,"id")) { cur_word = get_cur_word_str(&cur_line); if (string_equal(cur_word,"name")) { AnsiString EngineName = cur_line; MainForm->lbEngineName->Caption = EngineName; } } if (string_equal(cur_word,"uciok")) { if (MainForm->MultiPV > 1) { Process->Send("setoption name MultiPV value " + IntToStr(MainForm->MultiPV)); Sleep(100); Process->Get(buf); } Process->Send("setoption name Hash value " + IntToStr(MainForm->HashSize)); return; } } } } } while (true); }
int main(int argc, char **argv) { short *samples; int file_descriptor; struct stat file_stats; int offset = 0; if (argc == 1) { printf("%s <audio file>\n", argv[0]); return EXIT_FAILURE; } file_descriptor = open(argv[1], O_RDONLY); if (file_descriptor == -1) { perror("Failed to open audio file"); return EXIT_FAILURE; } if (fstat(file_descriptor, &file_stats)) { perror("Failed to stat file"); return EXIT_FAILURE; } if (!strncmp((argv[1] + strlen(argv[1] - 4)), ".wav", 4)) { offset = 44; } samples = mmap(0, file_stats.st_size, PROT_READ, MAP_SHARED, file_descriptor, offset); if (samples == MAP_FAILED) { close(file_descriptor); perror("Failed to map file"); return EXIT_FAILURE; } printf("File length: %d\n", (int) (file_stats.st_size - offset)); PcmData *pcm = pcm_init(samples, (file_stats.st_size - offset) / 2, false); printf("Decoding swipe using Square algorithm...\n"); SquareDecoder *decoder = square_init(pcm); square_decode_swipe(decoder); if (decoder->lastError == SwipeError_Success) { printf("Decoded card characters: %s\n", decoder->cardString); } else { printf( "Card decoding using Square algorithm has failed! Using UniMag algorithm...\n"); char *byteSamples = (char*) malloc( (file_stats.st_size - offset) * sizeof(char)); char *buffer = (char*) samples; int i = 0; for (i = offset; i <= file_stats.st_size; ++i) { byteSamples[i] = buffer[i]; } char *cardString = unimag_decode(byteSamples, file_stats.st_size - offset); printf("Decoded card characters: %s\n", cardString); free(byteSamples); free(cardString); } pcm_free(pcm); square_free(decoder); if (munmap(samples, file_stats.st_size) == -1) { perror("Failed to unmap file"); } close(file_descriptor); return EXIT_SUCCESS; }
void CompressMoves::Init() { cr.Init(); ((thc::ChessPosition)cr).Init(); for( int i=0; i<64; i++ ) trackers[i] = NULL; square_init( TI_K, 'K', thc::e1 ); square_init( TI_KN, 'N', thc::g1 ); square_init( TI_QN, 'N', thc::b1 ); square_init( TI_KR, 'R', thc::h1 ); square_init( TI_QR, 'R', thc::a1 ); square_init( TI_KB, 'B', thc::f1 ); square_init( TI_QB, 'B', thc::c1 ); square_init( TI_Q, 'Q', thc::d1 ); white_pieces[TI_Q].shadow_rank = &white_pieces[TI_KN]; white_pieces[TI_KN].shadow_owner = &white_pieces[TI_Q]; white_pieces[TI_Q].shadow_file = &white_pieces[TI_QN]; white_pieces[TI_QN].shadow_owner = &white_pieces[TI_Q]; square_init( TI_AP, 'P', thc::a2 ); square_init( TI_BP, 'P', thc::b2 ); square_init( TI_CP, 'P', thc::c2 ); square_init( TI_DP, 'P', thc::d2 ); square_init( TI_EP, 'P', thc::e2 ); square_init( TI_FP, 'P', thc::f2 ); square_init( TI_GP, 'P', thc::g2 ); square_init( TI_HP, 'P', thc::h2 ); square_init( TI_K, 'k', thc::e8 ); square_init( TI_KN, 'n', thc::g8 ); square_init( TI_QN, 'n', thc::b8 ); square_init( TI_KR, 'r', thc::h8 ); square_init( TI_QR, 'r', thc::a8 ); square_init( TI_KB, 'b', thc::f8 ); square_init( TI_QB, 'b', thc::c8 ); square_init( TI_Q, 'q', thc::d8 ); black_pieces[TI_Q].shadow_rank = &black_pieces[TI_KN]; black_pieces[TI_KN].shadow_owner = &black_pieces[TI_Q]; black_pieces[TI_Q].shadow_file = &black_pieces[TI_QN]; black_pieces[TI_QN].shadow_owner = &black_pieces[TI_Q]; square_init( TI_AP, 'p', thc::a7 ); square_init( TI_BP, 'p', thc::b7 ); square_init( TI_CP, 'p', thc::c7 ); square_init( TI_DP, 'p', thc::d7 ); square_init( TI_EP, 'p', thc::e7 ); square_init( TI_FP, 'p', thc::f7 ); square_init( TI_GP, 'p', thc::g7 ); square_init( TI_HP, 'p', thc::h7 ); }
int main(int argc, char * argv[]) { // board_t board[1]; // init Init = false; #ifdef _WIN32 signal(SIGINT,SIG_IGN); signal(SIGTERM,SIG_IGN); #ifdef SIGPIPE signal(SIGPIPE,SIG_IGN); #endif #endif util_init(); printf("PolyGlot %s by Fabien Letouzey\n",Version); option_init(); uci_options_init(); square_init(); piece_init(); attack_init(); hash_init(); my_random_init(); // build book if (argc >= 2 && my_string_equal(argv[1],"make-book")) { book_make(argc,argv); return EXIT_SUCCESS; } if (argc >= 2 && my_string_equal(argv[1],"merge-book")) { book_merge(argc,argv); return EXIT_SUCCESS; } // read options if (argc == 2) option_set("OptionFile",argv[1]); // HACK for compatibility parse_option(); // HACK: also launches the engine // EPD test if (argc >= 2 && my_string_equal(argv[1],"epd-test")) { epd_test(argc,argv); return EXIT_SUCCESS; } // opening book book_clear(); if (option_get_bool("Book")){ if (book_open(option_get_string("BookFile"))) option_set("Book","false");//some error,set to false } //adapter_loop(); #ifdef _WIN32 Engine_ready_ok=CreateEvent(NULL,FALSE,FALSE,NULL); Engine_sync_stop = CreateEvent(NULL,FALSE,FALSE,NULL); // all set and done.lets open a thread for fun DWORD dwThreadID; HANDLE hThread; hThread= CreateThread( NULL, //default security attributes 0, //default stacksize ThreadFunc, //The thread function! &sCommand, //the commands for the thread function 0, //default creation flags &dwThreadID); //the thread identifier Idle500msecs();// if(hThread==NULL){ my_log("CreateThread failed\n"); } #endif adapter_loop(); engine_send(Engine,"quit"); engine_close(Engine); #ifdef _WIN32 CloseHandle(hThread); //close the thread; #endif return EXIT_SUCCESS; }
void use_square_OK() { int i; square_init(2, i); }