Exemplo n.º 1
0
Arquivo: ui.cpp Projeto: pd/benthos
///////////////////////////////
// sends the 'info' command to the UI, reporting the current
// search status.
///////////////////////////////
void
report_search_info(void)
{
	clock_t time = clock() - searchInfo->startTime;
	float nps = (float)searchInfo->nodes / (time / 1000);
	int rmn = searchInfo->curRootMoveNum;
	int score = searchInfo->bestRootScore;

	if (suppressSearchStatus || time < 1000)
		return;

	printf("info currmove %s currmovenumber %d\n",
			move2str(searchInfo->rootMoves[rmn].move), rmn + 1);
	printf("info depth %d ", searchInfo->depth);
	if (abs(score) < MATE - 200)
		printf("score cp %d ", score);
	else
		printf("score mate %d ", score > 0 ? (score - MATE + 1) / 2 : (score + MATE) / 2);
	printf("time %lu nodes %llu nps %.0f pv %s\n",
			time, searchInfo->nodes, nps, move2str(searchInfo->bestRootMove));
	fflush(stdout);
}
Exemplo n.º 2
0
void do_move(char *ini_moves, int from, int sz)
{
    char pv[6], str_move[6];
    int i, to;

    for (i = 0; i < sz; i++)
    {
        pv[i] = ini_moves[from + i];
    }
    pv[i] = 0;

    from = board.idx_moves;
    movegen();
    to = board.idx_moves;
    for (i = from; i < to; i++)
    {
        if (!strcmp(move2str(board.moves[i], str_move), pv))
        {
            make_move(board.moves[i]);
            return;
        }
    }
}
Exemplo n.º 3
0
/*Inizializza la ricerca e gestisce l'iterative deeping*/
unsigned int find_best_move(const int output_mode,const int search_mode) {
	int depth, score, i,c,d,start_depth;
	int alpha, beta;
	MOVE m = {0};

	/*inizializzazioni varie*/
	tree.start_time = time_elapsed();
	tree.stop_time = tree.start_time + tree.delta_time;
	Ply = 0;
	Nodes = 0;
	tree.abort_search = 0;
	start_depth=tree.ponder_start_depth-1;
	alpha = -INF;
	beta = +INF;

	do {
		if (search_mode==CONTINUE_SEARCH) break;
		start_depth=1;
		tree.ponder_start_depth=1;
	for (i=0;i<MAX_PLY;i++) {
		tree.old_pv[i].mi=0;
		tree.k_heuristic[i].m1.mi=0;
		tree.k_heuristic[i].m2.mi=0;
		tree.k_heuristic[i].score1=0;
		tree.k_heuristic[i].score2=0;
		for (c=0;c<MAX_PLY;c++) tree.pv[i][c].mi=0;
	}
	for (i=0;i<256;i++) {
		for (c=0;c<256;c++) {
			tree.h_heuristic[i][c]=0;
		}	
	}
	for (i=0;i<64;i++) {
		for (c=0;c<64;c++) {
			for (d=0;d<256;d++)tree.c_heuristic[i][c][d].mi=0;
		}	
	}
	if (mizar.o.use_hash) reset_tt();
	}while (0);

	
	

	/*Precalcoliamo*/
	Phase(WHITE) = eval_phase(WHITE);
	Phase(BLACK) = eval_phase(BLACK);

	/*Prepariamo il nodo radice*/
	root();
	Nodes=0;

	if (output_mode == IO_CONSOLE)
		printf("ply  score      time      nodes pv\n");

	/*iterative deeping*/ 
	for (depth = start_depth;depth <= tree.max_depth;depth++) {
			
			tree.ponder_start_depth=depth;

			tree.follow_pv = 1;

			score = search_root( alpha, beta, depth);

			if (tree.abort_search)
				break;

			if (score<=alpha || score >=beta) {
				alpha = -INF;
				beta = +INF;
				tree.follow_pv = 1;
				score = search_root( alpha, beta, depth);
				if (tree.abort_search)
				break;
			} 
			else {
				alpha = score - ASPIRATION_W;
				beta = score + ASPIRATION_W;				
				} 

			m.mi = tree.pv[0][0].mi;

			for (i=0;i<MAX_PLY;i++)
				tree.old_pv[i].mi=0;

			sort_root_nodes();

			for (i = 0;i < tree.pv_lenght[0];i++)
				tree.old_pv[i] = tree.pv[0][i];


			if (output_mode == IO_CONSOLE) {
					printf("%3d  %5d  %8d  %9d", depth, score, (time_elapsed() - tree.start_time) / 100, Nodes);
					}

			else if (output_mode == IO_WINBOARD) {
					printf("%d %d %d %d", depth, score, (time_elapsed() - tree.start_time) / 10, Nodes);
					}

			if (output_mode) {
				if (!mizar.o.only_pv) printf(" Phs:%d Phx:%d",Phase(Side),Phase(Xside));
					for (i = 0;i < tree.pv_lenght[0];i++)
						printf(" %s", move2str(tree.old_pv[i]));

					printf("\n");

					fflush(stdout);
					}

			}
	return (m.mi);
	}
Exemplo n.º 4
0
Arquivo: ui.cpp Projeto: pd/benthos
///////////////////////////////
// reads in the time controls (a hassle), stores the information
// into the search info structure, then calls the search.
///////////////////////////////
static bool
cmd_go(const char *args)
{
	int mtg = 0, depthmax = 0;
	int wtime = 0, btime = 0, winc = 0, binc = 0;
	long nodemax = 0, movetime = 0;
	int time, inc;

	if (rootPosition == NULL) {
		cout << "Invalid position: can't go." << endl;
		return false;
	}

	if (args == NULL || strstr(args, "infinite") != NULL)
		searchInfo->inf = true;
	else {
		searchInfo->inf = false;
		if (get_long_arg(args, "movetime", movetime))
			searchInfo->endTime = clock() + movetime;
		else {
			get_int_arg(args,  "wtime",     wtime);
			get_int_arg(args,  "btime",     btime);
			get_int_arg(args,  "winc",      winc);
			get_int_arg(args,  "binc",      binc);
			get_int_arg(args,  "movestogo", mtg);
			get_int_arg(args,  "depth",     depthmax);
			get_long_arg(args, "nodes",     nodemax);

			if (depthmax != 0)
				searchInfo->depthLimit = depthmax;
			if (nodemax != 0)
				searchInfo->nodeLimit = nodemax;

			// found this time calculation in scatha.
			// much better than what i came up with.
			if (Stm(0) == WHITE) {
				time = wtime;
				inc  = winc;
			} else {
				time = btime;
				inc  = binc;
			}

			if (mtg == 0) {
				if (inc != 0)
					time = time / 30 + inc;
				else
					time = time / 40;
			} else {
				if (mtg == 1)
					time = time / 2;
				else
					time = time / Min(mtg, 20);
			}

			searchInfo->endTime = clock() + time;
		}
	}

	move_t move = search(rootPosition);
	if (!move) {
		cout << "Error: Search failed to find a move..." << endl;
		return false;
	}

	make_history_move(rootPosition, move);
	cout << "bestmove " << move2str(move) << endl;
	cout.flush();
	return true;
}