gochatai/pachi_py/pachi/uct/search.c
/* Determine whether we should terminate the search later than expected. */
Determine whether we should terminate the search later than expected.
Determine whether we should terminate the search later than expected .
static bool
uct_search_keep_looking(struct uct *u, struct tree *t, struct board *b,
		struct time_info *ti, struct time_stop *stop,
		struct tree_node *best, struct tree_node *best2,
		struct tree_node *bestr, struct tree_node *winner, int i)
{
	if (!best) {
		if (UDEBUGL(2))
			fprintf(stderr, "Did not find best move, still trying...\n");
		return true;
	}
	floating_t beta = 2 * (tree_node_get_value(t, 1, best->u.value) - 0.5);
	if (ti->dim == TD_WALLTIME && beta > 0) {
		double good_enough = stop->desired.time * beta + stop->worst.time * (1 - beta);
		double elapsed = time_now() - ti->len.t.timer_start;
		if (elapsed > good_enough) return false;
	}
	if (u->best2_ratio > 0) {
		if (best2 && best2->u.playouts
		    && (double)best->u.playouts / best2->u.playouts < u->best2_ratio) {
			if (UDEBUGL(2))
				fprintf(stderr, "Best2 ratio %f < threshold %f\n",
					(double)best->u.playouts / best2->u.playouts,
					u->best2_ratio);
			return true;
		}
	}
	if (u->bestr_ratio > 0) {
		if (bestr && bestr->u.playouts
		    && fabs((double)best->u.value - bestr->u.value) > u->bestr_ratio) {
			if (UDEBUGL(2))
				fprintf(stderr, "Bestr delta %f > threshold %f\n",
					fabs((double)best->u.value - bestr->u.value),
					u->bestr_ratio);
			return true;
		}
	}
	if (winner && winner != best) {
		if (UDEBUGL(2))
			fprintf(stderr, "[%d] best %3s [%d] %f != winner %3s [%d] %f\n", i,
				coord2sstr(node_coord(best), t->board),
				best->u.playouts, tree_node_get_value(t, 1, best->u.value),
				coord2sstr(node_coord(winner), t->board),
				winner->u.playouts, tree_node_get_value(t, 1, winner->u.value));
		return true;
	}
	return false;
}
static bool uct_search_keep_looking ( struct uct * u , struct tree * t , struct board * b , struct time_info * ti , struct time_stop * stop , struct tree_node * best , struct tree_node * best2 , struct tree_node * bestr , struct tree_node * winner , int i ) { if ( ! best ) { if ( UDEBUGL ( 2 ) ) fprintf ( stderr , " \n " ) ; return true ; } floating_t beta = 2 * ( tree_node_get_value ( t , 1 , best -> u . value ) - 0.5 ) ; if ( ti -> dim == TD_WALLTIME && beta > 0 ) { double good_enough = stop -> desired . time * beta + stop -> worst . time * ( 1 - beta ) ; double elapsed = time_now ( ) - ti -> len . t . timer_start ; if ( elapsed > good_enough ) return false ; } if ( u -> best2_ratio > 0 ) { if ( best2 && best2 -> u . playouts && ( double ) best -> u . playouts / best2 -> u . playouts < u -> best2_ratio ) { if ( UDEBUGL ( 2 ) ) fprintf ( stderr , " \n " , ( double ) best -> u . playouts / best2 -> u . playouts , u -> best2_ratio ) ; return true ; } } if ( u -> bestr_ratio > 0 ) { if ( bestr && bestr -> u . playouts && fabs ( ( double ) best -> u . value - bestr -> u . value ) > u -> bestr_ratio ) { if ( UDEBUGL ( 2 ) ) fprintf ( stderr , " \n " , fabs ( ( double ) best -> u . value - bestr -> u . value ) , u -> bestr_ratio ) ; return true ; } } if ( winner && winner != best ) { if ( UDEBUGL ( 2 ) ) fprintf ( stderr , " \n " , i , coord2sstr ( node_coord ( best ) , t -> board ) , best -> u . playouts , tree_node_get_value ( t , 1 , best -> u . value ) , coord2sstr ( node_coord ( winner ) , t -> board ) , winner -> u . playouts , tree_node_get_value ( t , 1 , winner -> u . value ) ) ; return true ; } return false ; }
Determine whether we should terminate the search later than expected.
Determine whether we should terminate the search later than expected .
/* Do not waste time if we are winning. Spend up to worst time if
	 * we are unsure, but only desired time if we are sure of winning. */ /* Check best/best2 simulations ratio. If the
		 * two best moves give very similar results,
		 * keep simulating. */ /* Check best, best_best value difference. If the best move
		 * and its best child do not give similar enough results,
		 * keep simulating. */ /* Keep simulating if best explored
		 * does not have also highest value. */ /* No reason to keep simulating, bye. */