gochatai/pachi_py/pachi/playout/moggy.c
/* Pick a move from queue q, giving different likelihoods to moves
 * based on their tags. */
Pick a move from queue q, giving different likelihoods to moves
based on their tags.
Pick a move from queue q giving different likelihoods to moves based on their tags .
coord_t
mq_tagged_choose(struct playout_policy *p, struct board *b, enum stone to_play, struct move_queue *q)
{
	struct moggy_policy *pp = p->data;
	for (unsigned int i = 0; i < q->moves; i++) {
		for (unsigned int j = i + 1; j < q->moves; j++) {
			if (q->move[i] != q->move[j])
				continue;
			q->tag[i] |= q->tag[j];
			q->moves--;
			q->tag[j] = q->tag[q->moves];
			q->move[j] = q->move[q->moves];
		}
	}
	fixp_t total = 0;
	fixp_t pd[q->moves];
	for (unsigned int i = 0; i < q->moves; i++) {
		double val = 1.0;
		assert(q->tag[i] != 0);
		for (int j = 0; j < MQ_MAX; j++)
			if (q->tag[i] & (1<<j)) {
				val *= pp->mq_prob[j];
			}
		pd[i] = double_to_fixp(val);
		total += pd[i];
	}
	total += double_to_fixp(pp->tenuki_prob);
	fixp_t stab = fast_irandom(total);
	if (PLDEBUGL(5)) {
		fprintf(stderr, "Pick (total %.3f stab %.3f): ", fixp_to_double(total), fixp_to_double(stab));
		for (unsigned int i = 0; i < q->moves; i++) {
			fprintf(stderr, "%s(%x:%.3f) ", coord2sstr(q->move[i], b), q->tag[i], fixp_to_double(pd[i]));
		}
		fprintf(stderr, "\n");
	}
	for (unsigned int i = 0; i < q->moves; i++) {
		if (stab < pd[i])
			return q->move[i];
		stab -= pd[i];
	}
	assert(stab < double_to_fixp(pp->tenuki_prob));
	return pass;
}
coord_t mq_tagged_choose ( struct playout_policy * p , struct board * b , enum stone to_play , struct move_queue * q ) { struct moggy_policy * pp = p -> data ; for ( unsigned int i = 0 ; i < q -> moves ; i ++ ) { for ( unsigned int j = i + 1 ; j < q -> moves ; j ++ ) { if ( q -> move [ i ] != q -> move [ j ] ) continue ; q -> tag [ i ] |= q -> tag [ j ] ; q -> moves -- ; q -> tag [ j ] = q -> tag [ q -> moves ] ; q -> move [ j ] = q -> move [ q -> moves ] ; } } fixp_t total = 0 ; fixp_t pd [ q -> moves ] ; for ( unsigned int i = 0 ; i < q -> moves ; i ++ ) { double val = 1.0 ; assert ( q -> tag [ i ] != 0 ) ; for ( int j = 0 ; j < MQ_MAX ; j ++ ) if ( q -> tag [ i ] & ( 1 << j ) ) { val *= pp -> mq_prob [ j ] ; } pd [ i ] = double_to_fixp ( val ) ; total += pd [ i ] ; } total += double_to_fixp ( pp -> tenuki_prob ) ; fixp_t stab = fast_irandom ( total ) ; if ( PLDEBUGL ( 5 ) ) { fprintf ( stderr , " " , fixp_to_double ( total ) , fixp_to_double ( stab ) ) ; for ( unsigned int i = 0 ; i < q -> moves ; i ++ ) { fprintf ( stderr , " " , coord2sstr ( q -> move [ i ] , b ) , q -> tag [ i ] , fixp_to_double ( pd [ i ] ) ) ; } fprintf ( stderr , " \n " ) ; } for ( unsigned int i = 0 ; i < q -> moves ; i ++ ) { if ( stab < pd [ i ] ) return q -> move [ i ] ; stab -= pd [ i ] ; } assert ( stab < double_to_fixp ( pp -> tenuki_prob ) ) ; return pass ; }
Pick a move from queue q, giving different likelihoods to moves
 based on their tags.
Pick a move from queue q giving different likelihoods to moves based on their tags .
/* First, merge all entries for a move. */ /* We use a naive O(N^2) since the average length of the queue
	 * is about 1.4. */ /* Now, construct a probdist. */ //fprintf(stderr, "%s(%x) %d %f *= %f\n", coord2sstr(q->move[i], b), q->tag[i], j, val, pp->mq_prob[j]); /* Finally, pick a move! */ //fprintf(stderr, "%s(%x) %f (%f/%f)\n", coord2sstr(q->move[i], b), q->tag[i], fixp_to_double(stab), fixp_to_double(pd[i]), fixp_to_double(total)); /* Tenuki. */