Exemplo n.º 1
0
int main(int argc, char *argv[]) {

	// init

	util_init();
	my_random_init(); // for opening book

	printf(
		"Gambit Fruit based on Fruit 2.1 and Toga by Ryan Benitez, Thomas Gaksch and Fabien Letouzey\nEdit by Evgeniy Zheltonozhskiy\n");

	// early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

	option_init();

	square_init();
	piece_init();
	pawn_init_bit();
	value_init();
	vector_init();
	attack_init();
	move_do_init();

	random_init();
	hash_init();

	trans_init(Trans);
	book_init();

	// loop
	loop();

	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int main(int argc, char * argv[]) {

   // init

   util_init();
   my_random_init(); // for opening book

   printf("Toga II 1.2.1a UCI based on Fruit 2.1 by Thomas Gaksch and Fabien Letouzey. Settings by Dieter Eberle\n");

   // early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

   option_init();

   square_init();
   piece_init();
   pawn_init_bit();
   value_init();
   vector_init();
   attack_init();
   move_do_init();

   random_init();
   hash_init();

   trans_init(Trans);
   book_init();

   // loop

   loop();

   return EXIT_SUCCESS;
}
Exemplo n.º 3
0
/*
 * Calcule les limites en terme de largeur et de hauteur de
 * la forme du dragon. Requis pour allouer la matrice de dessin.
 */
int dragon_limits_pthread(limits_t *limits, uint64_t size, int nb_thread)
{
	printf("Started dragon_limits_pthread\n");
	uint64_t block_size = size / nb_thread;
	uint64_t remainder  = size - (block_size * nb_thread);
	//printf("Total size: %" PRIu64 "\n",size);
	//printf("Block size : %" PRIu64 "\n", block_size);
	//if (remainder != 0U)
	//	printf("Remainder: %" PRIu64 "\n", remainder);
	
	int ret = 0;
	pthread_t *threads = NULL;
	struct limit_data *thread_data = NULL;
	piece_t master;

	piece_init(&master);

	if ((threads = calloc(nb_thread, sizeof(pthread_t))) == NULL)
		goto err;

	if ((thread_data = calloc(nb_thread, sizeof(struct limit_data))) == NULL)
		goto err;

	/* 1. Lancement du calcul en parallèle avec dragon_limit_worker */
	int i, j;
	for(i = 0, j = 0; i < nb_thread; ++i) {
        piece_init(&thread_data[i].piece);
	    thread_data[i].id = i;
        thread_data[i].start = i * block_size + j;
		if (remainder != 0U)
		{
			++j;
			--remainder;
		}
        thread_data[i].end = (i+1) * block_size + j;
       	//printf("thread_data: Start=%" PRIu64 ", \tEnd=%" PRIu64 ", \tID=%d\n", thread_data[i].start, thread_data[i].end, thread_data[i].id);
        piece_init(&thread_data[i].piece);
        pthread_create(&threads[i], NULL, dragon_limit_worker, &thread_data[i]);
	};

	/* 2. Attendre la fin du traitement */
 	for(i = 0; i < nb_thread; ++i) {
        pthread_join(threads[i], NULL);
	}

    /* 3. Fusion des pièces */
	for(i = 0; i < nb_thread; ++i) {
        piece_merge(&master, thread_data[i].piece);
    };
	printf("Finished merging pieces\n");
	printf("Finished dragon_limits_pthread\n");
	
done:
	FREE(threads);
	FREE(thread_data);
	*limits = master.limits;
	return ret;
err:
	ret = -1;
	goto done;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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;
}