gochatai/pachi_py/pachi/chat.c
/* Reply to a chat. When not playing, color is S_NONE and all remaining parameters are undefined.
 * If some matching entries have not yet been displayed we pick randomly among them. Otherwise
 * we pick randomly among all matching entries. */
Reply to a chat. When not playing, color is S_NONE and all remaining parameters are undefined.
If some matching entries have not yet been displayed we pick randomly among them. Otherwise
we pick randomly among all matching entries.
Reply to a chat . When not playing color is S_NONE and all remaining parameters are undefined . If some matching entries have not yet been displayed we pick randomly among them . Otherwise we pick randomly among all matching entries .
char
*generic_chat(struct board *b, bool opponent, char *from, char *cmd, enum stone color, coord_t move,
	      int playouts, int machines, int threads, double winrate, double extra_komi) {
	static char reply[1024];
	if (!chat_table) {
		if (strncasecmp(cmd, "winrate", 7)) return NULL;
		if (color == S_NONE) return not_playing;
		snprintf(reply, 512, "In %d playouts at %d threads, %s %s can win with %.1f%% probability",
			 playouts, threads, stone2str(color), coord2sstr(move, b), 100*winrate);
		if (fabs(extra_komi) >= 0.5) {
			snprintf(reply + strlen(reply), 510, ", while self-imposing extra komi %.1f", extra_komi);
		}
		strcat(reply, ".");
		return reply;
	}
	int matches = 0;
	int undisplayed = 0;
	for (struct chat *entry = chat_table; entry->regex[0]; entry++) {
		entry->match = false;
		if (color != S_NONE) {
			if (winrate < entry->minwin) continue;
			if (winrate > entry->maxwin) continue;
		}
		if (entry->from[0] && strcmp(entry->from, from)) continue;
		if (regexec(&entry->preg, cmd, 0, NULL, 0)) continue;
		entry->match = true;
		matches++;
		if (!entry->displayed) undisplayed++;
	}
	if (matches == 0) return default_reply;
	int choices = undisplayed > 0 ? undisplayed : matches;
	int index = fast_random(choices);
	for (struct chat *entry = chat_table; entry->regex[0]; entry++) {
		if (!entry->match) continue;
		if (undisplayed > 0 && entry->displayed) continue;
		if (--index < 0) {
			entry->displayed = true;
			snprintf(reply, sizeof(reply), entry->reply, 100*winrate);
			return reply;
		}
	}
	assert(0);
	return NULL;
}
char * generic_chat ( struct board * b , bool opponent , char * from , char * cmd , enum stone color , coord_t move , int playouts , int machines , int threads , double winrate , double extra_komi ) { static char reply [ 1024 ] ; if ( ! chat_table ) { if ( strncasecmp ( cmd , " " , 7 ) ) return NULL ; if ( color == S_NONE ) return not_playing ; snprintf ( reply , 512 , " " , playouts , threads , stone2str ( color ) , coord2sstr ( move , b ) , 100 * winrate ) ; if ( fabs ( extra_komi ) >= 0.5 ) { snprintf ( reply + strlen ( reply ) , 510 , " " , extra_komi ) ; } strcat ( reply , " " ) ; return reply ; } int matches = 0 ; int undisplayed = 0 ; for ( struct chat * entry = chat_table ; entry -> regex [ 0 ] ; entry ++ ) { entry -> match = false ; if ( color != S_NONE ) { if ( winrate < entry -> minwin ) continue ; if ( winrate > entry -> maxwin ) continue ; } if ( entry -> from [ 0 ] && strcmp ( entry -> from , from ) ) continue ; if ( regexec ( & entry -> preg , cmd , 0 , NULL , 0 ) ) continue ; entry -> match = true ; matches ++ ; if ( ! entry -> displayed ) undisplayed ++ ; } if ( matches == 0 ) return default_reply ; int choices = undisplayed > 0 ? undisplayed : matches ; int index = fast_random ( choices ) ; for ( struct chat * entry = chat_table ; entry -> regex [ 0 ] ; entry ++ ) { if ( ! entry -> match ) continue ; if ( undisplayed > 0 && entry -> displayed ) continue ; if ( -- index < 0 ) { entry -> displayed = true ; snprintf ( reply , sizeof ( reply ) , entry -> reply , 100 * winrate ) ; return reply ; } } assert ( 0 ) ; return NULL ; }
Reply to a chat.
Reply to a chat .