Use local test&set instead of global mutex to expand a node.
[pachi.git] / uct / uct.c
blobfae3bd21d7d9cf56307ab4c6a2e8a37e5fabc954
1 #include <assert.h>
2 #include <pthread.h>
3 #include <signal.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 #define DEBUG
10 #include "debug.h"
11 #include "board.h"
12 #include "gtp.h"
13 #include "move.h"
14 #include "mq.h"
15 #include "playout.h"
16 #include "playout/elo.h"
17 #include "playout/moggy.h"
18 #include "playout/light.h"
19 #include "random.h"
20 #include "tactics.h"
21 #include "uct/internal.h"
22 #include "uct/prior.h"
23 #include "uct/tree.h"
24 #include "uct/uct.h"
25 #include "uct/walk.h"
27 struct uct_policy *policy_ucb1_init(struct uct *u, char *arg);
28 struct uct_policy *policy_ucb1amaf_init(struct uct *u, char *arg);
31 #define MC_GAMES 80000
32 #define MC_GAMELEN MAX_GAMELEN
34 /* How big proportion of ownermap counts must be of one color to consider
35 * the point sure. */
36 #define GJ_THRES 0.8
37 /* How many games to consider at minimum before judging groups. */
38 #define GJ_MINGAMES 500
41 static void
42 setup_state(struct uct *u, struct board *b, enum stone color)
44 u->t = tree_init(b, color);
45 if (u->force_seed)
46 fast_srandom(u->force_seed);
47 if (UDEBUGL(0))
48 fprintf(stderr, "Fresh board with random seed %lu\n", fast_getseed());
49 //board_print(b, stderr);
50 if (!u->no_book && b->moves == 0) {
51 assert(color == S_BLACK);
52 tree_load(u->t, b);
56 static void
57 reset_state(struct uct *u)
59 assert(u->t);
60 tree_done(u->t); u->t = NULL;
63 static void
64 prepare_move(struct engine *e, struct board *b, enum stone color)
66 struct uct *u = e->data;
68 if (u->t) {
69 /* Verify that we have sane state. */
70 assert(b->es == u);
71 assert(u->t && b->moves);
72 if (color != stone_other(u->t->root_color)) {
73 fprintf(stderr, "Fatal: Non-alternating play detected %d %d\n",
74 color, u->t->root_color);
75 exit(1);
78 } else {
79 /* We need fresh state. */
80 b->es = u;
81 setup_state(u, b, color);
84 if (u->dynkomi && u->dynkomi > b->moves && (color & u->dynkomi_mask))
85 u->t->extra_komi = uct_get_extra_komi(u, b);
87 u->ownermap.playouts = 0;
88 memset(u->ownermap.map, 0, board_size2(b) * sizeof(u->ownermap.map[0]));
91 static void
92 dead_group_list(struct uct *u, struct board *b, struct move_queue *mq)
94 struct group_judgement gj;
95 gj.thres = GJ_THRES;
96 gj.gs = alloca(board_size2(b) * sizeof(gj.gs[0]));
97 board_ownermap_judge_group(b, &u->ownermap, &gj);
98 groups_of_status(b, &gj, GS_DEAD, mq);
101 bool
102 uct_pass_is_safe(struct uct *u, struct board *b, enum stone color)
104 if (u->ownermap.playouts < GJ_MINGAMES)
105 return false;
107 struct move_queue mq = { .moves = 0 };
108 if (!u->pass_all_alive)
109 dead_group_list(u, b, &mq);
110 return pass_is_safe(b, color, &mq);
114 static void
115 uct_printhook_ownermap(struct board *board, coord_t c, FILE *f)
117 struct uct *u = board->es;
118 assert(u);
119 const char chr[] = ":XO,"; // dame, black, white, unclear
120 const char chm[] = ":xo,";
121 char ch = chr[board_ownermap_judge_point(&u->ownermap, c, GJ_THRES)];
122 if (ch == ',') { // less precise estimate then?
123 ch = chm[board_ownermap_judge_point(&u->ownermap, c, 0.67)];
125 fprintf(f, "%c ", ch);
128 static char *
129 uct_notify_play(struct engine *e, struct board *b, struct move *m)
131 struct uct *u = e->data;
132 if (!u->t) {
133 /* No state, create one - this is probably game beginning
134 * and we need to load the opening book right now. */
135 prepare_move(e, b, m->color);
136 assert(u->t);
139 if (is_resign(m->coord)) {
140 /* Reset state. */
141 reset_state(u);
142 return NULL;
145 /* Promote node of the appropriate move to the tree root. */
146 assert(u->t->root);
147 if (!tree_promote_at(u->t, b, m->coord)) {
148 if (UDEBUGL(0))
149 fprintf(stderr, "Warning: Cannot promote move node! Several play commands in row?\n");
150 reset_state(u);
151 return NULL;
154 return NULL;
157 static char *
158 uct_chat(struct engine *e, struct board *b, char *cmd)
160 struct uct *u = e->data;
161 static char reply[1024];
163 cmd += strspn(cmd, " \n\t");
164 if (!strncasecmp(cmd, "winrate", 7)) {
165 if (!u->t)
166 return "no game context (yet?)";
167 enum stone color = u->t->root_color;
168 struct tree_node *n = u->t->root;
169 snprintf(reply, 1024, "In %d playouts, %s %s can win with %.2f%% probability",
170 n->u.playouts * (u->thread_model == TM_ROOT ? u->threads : 1),
171 stone2str(color), coord2sstr(n->coord, b),
172 tree_node_get_value(u->t, -1, n->u.value) * 100);
173 if (abs(u->t->extra_komi) >= 0.5) {
174 sprintf(reply + strlen(reply), ", while self-imposing extra komi %.1f",
175 u->t->extra_komi);
177 strcat(reply, ".");
178 return reply;
180 return NULL;
183 static void
184 uct_dead_group_list(struct engine *e, struct board *b, struct move_queue *mq)
186 struct uct *u = e->data;
187 if (u->pass_all_alive)
188 return; // no dead groups
190 bool mock_state = false;
192 if (!u->t) {
193 /* No state, but we cannot just back out - we might
194 * have passed earlier, only assuming some stones are
195 * dead, and then re-connected, only to lose counting
196 * when all stones are assumed alive. */
197 /* Mock up some state and seed the ownermap by few
198 * simulations. */
199 prepare_move(e, b, S_BLACK); assert(u->t);
200 for (int i = 0; i < GJ_MINGAMES; i++)
201 uct_playout(u, b, S_BLACK, u->t);
202 mock_state = true;
205 dead_group_list(u, b, mq);
207 if (mock_state) {
208 /* Clean up the mock state in case we will receive
209 * a genmove; we could get a non-alternating-move
210 * error from prepare_move() in that case otherwise. */
211 reset_state(u);
215 static void
216 playout_policy_done(struct playout_policy *p)
218 if (p->done) p->done(p);
219 if (p->data) free(p->data);
220 free(p);
223 static void
224 uct_done(struct engine *e)
226 /* This is called on engine reset, especially when clear_board
227 * is received and new game should begin. */
228 struct uct *u = e->data;
229 if (u->t) reset_state(u);
230 free(u->ownermap.map);
232 free(u->policy);
233 free(u->random_policy);
234 playout_policy_done(u->playout);
235 uct_prior_done(u->prior);
239 /* Set in main thread in case the playouts should stop. */
240 volatile sig_atomic_t uct_halt = 0;
241 /* ID of the running worker thread. */
242 __thread int thread_id = -1;
244 static pthread_mutex_t finish_mutex = PTHREAD_MUTEX_INITIALIZER;
245 static pthread_cond_t finish_cond = PTHREAD_COND_INITIALIZER;
246 static volatile int finish_thread;
247 static pthread_mutex_t finish_serializer = PTHREAD_MUTEX_INITIALIZER;
249 struct spawn_ctx {
250 int tid;
251 struct uct *u;
252 struct board *b;
253 enum stone color;
254 struct tree *t;
255 unsigned long seed;
256 int games;
259 static void *
260 spawn_helper(void *ctx_)
262 struct spawn_ctx *ctx = ctx_;
263 /* Setup */
264 fast_srandom(ctx->seed);
265 thread_id = ctx->tid;
266 /* Run */
267 ctx->games = uct_playouts(ctx->u, ctx->b, ctx->color, ctx->t, ctx->games);
268 /* Finish */
269 pthread_mutex_lock(&finish_serializer);
270 pthread_mutex_lock(&finish_mutex);
271 finish_thread = ctx->tid;
272 pthread_cond_signal(&finish_cond);
273 pthread_mutex_unlock(&finish_mutex);
274 return ctx;
277 static int
278 uct_playouts_parallel(struct uct *u, struct board *b, enum stone color, struct tree *t, int games, bool shared_tree)
280 assert(u->threads > 0);
281 assert(u->parallel_tree == shared_tree);
283 int played_games = 0;
284 pthread_t threads[u->threads];
285 int joined = 0;
287 uct_halt = 0;
288 pthread_mutex_lock(&finish_mutex);
289 /* Spawn threads... */
290 for (int ti = 0; ti < u->threads; ti++) {
291 struct spawn_ctx *ctx = malloc(sizeof(*ctx));
292 ctx->u = u; ctx->b = b; ctx->color = color;
293 ctx->t = shared_tree ? t : tree_copy(t);
294 ctx->tid = ti; ctx->games = games;
295 ctx->seed = fast_random(65536) + ti;
296 pthread_create(&threads[ti], NULL, spawn_helper, ctx);
297 if (UDEBUGL(2))
298 fprintf(stderr, "Spawned thread %d\n", ti);
301 /* ...and collect them back: */
302 while (joined < u->threads) {
303 /* Wait for some thread to finish... */
304 pthread_cond_wait(&finish_cond, &finish_mutex);
305 /* ...and gather its remnants. */
306 struct spawn_ctx *ctx;
307 pthread_join(threads[finish_thread], (void **) &ctx);
308 played_games += ctx->games;
309 joined++;
310 #ifdef ROOT_PARALLEL
311 if (!shared_tree) {
312 tree_merge(t, ctx->t);
313 tree_done(ctx->t);
315 #endif
316 free(ctx);
317 if (UDEBUGL(2))
318 fprintf(stderr, "Joined thread %d\n", finish_thread);
319 /* Do not get stalled by slow threads. */
320 if (joined >= u->threads / 2)
321 uct_halt = 1;
322 pthread_mutex_unlock(&finish_serializer);
324 pthread_mutex_unlock(&finish_mutex);
326 #ifdef ROOT_PARALLEL
327 if (!shared_tree) {
328 /* XXX: Should this be done in shared trees as well? */
329 tree_normalize(t, u->threads);
331 #endif
332 return played_games;
336 typedef int (*uct_threaded_playouts)(struct uct *u, struct board *b, enum stone color, struct tree *t, int games);
338 static int
339 uct_playouts_none(struct uct *u, struct board *b, enum stone color, struct tree *t, int games)
341 return uct_playouts(u, b, color, t, games);
344 static int
345 uct_playouts_root(struct uct *u, struct board *b, enum stone color, struct tree *t, int games)
347 return uct_playouts_parallel(u, b, color, t, games, false);
350 static int
351 uct_playouts_tree(struct uct *u, struct board *b, enum stone color, struct tree *t, int games)
353 return uct_playouts_parallel(u, b, color, t, games, true);
356 static uct_threaded_playouts threaded_playouts[] = {
357 uct_playouts_none,
358 uct_playouts_root,
359 uct_playouts_tree,
360 uct_playouts_tree,
364 static coord_t *
365 uct_genmove(struct engine *e, struct board *b, enum stone color)
367 struct uct *u = e->data;
369 if (b->superko_violation) {
370 fprintf(stderr, "!!! WARNING: SUPERKO VIOLATION OCCURED BEFORE THIS MOVE\n");
371 fprintf(stderr, "Maybe you play with situational instead of positional superko?\n");
372 fprintf(stderr, "I'm going to ignore the violation, but note that I may miss\n");
373 fprintf(stderr, "some moves valid under this ruleset because of this.\n");
374 b->superko_violation = false;
377 /* Seed the tree. */
378 prepare_move(e, b, color);
379 assert(u->t);
381 /* Run the simulations. */
382 int games = u->games;
383 if (u->t->root->children) {
384 int delta = u->t->root->u.playouts * 2 / 3;
385 if (u->parallel_tree) delta /= u->threads;
386 games -= delta;
388 /* else this is highly read-out but dead-end branch of opening book;
389 * we need to start from scratch; XXX: Maybe actually base the readout
390 * count based on number of playouts of best node? */
391 if (games < u->games && UDEBUGL(2))
392 fprintf(stderr, "<pre-simulated %d games skipped>\n", u->games - games);
394 int played_games;
395 played_games = threaded_playouts[u->thread_model](u, b, color, u->t, games);
397 if (UDEBUGL(2))
398 tree_dump(u->t, u->dumpthres);
400 /* Choose the best move from the tree. */
401 struct tree_node *best = u->policy->choose(u->policy, u->t->root, b, color);
402 if (!best) {
403 reset_state(u);
404 return coord_copy(pass);
406 if (UDEBUGL(0)) {
407 uct_progress_status(u, u->t, color, played_games);
409 if (UDEBUGL(1))
410 fprintf(stderr, "*** WINNER is %s (%d,%d) with score %1.4f (%d/%d:%d games)\n",
411 coord2sstr(best->coord, b), coord_x(best->coord, b), coord_y(best->coord, b),
412 tree_node_get_value(u->t, 1, best->u.value),
413 best->u.playouts, u->t->root->u.playouts, played_games);
414 if (tree_node_get_value(u->t, 1, best->u.value) < u->resign_ratio && !is_pass(best->coord)) {
415 reset_state(u);
416 return coord_copy(resign);
419 /* If the opponent just passed and we win counting, always
420 * pass as well. */
421 if (b->moves > 1 && is_pass(b->last_move.coord)) {
422 /* Make sure enough playouts are simulated. */
423 while (u->ownermap.playouts < GJ_MINGAMES)
424 uct_playout(u, b, color, u->t);
425 if (uct_pass_is_safe(u, b, color)) {
426 if (UDEBUGL(0))
427 fprintf(stderr, "<Will rather pass, looks safe enough.>\n");
428 best->coord = pass;
432 tree_promote_node(u->t, best);
433 return coord_copy(best->coord);
437 bool
438 uct_genbook(struct engine *e, struct board *b, enum stone color)
440 struct uct *u = e->data;
441 if (!u->t) prepare_move(e, b, color);
442 assert(u->t);
444 threaded_playouts[u->thread_model](u, b, color, u->t, u->games);
446 tree_save(u->t, b, u->games / 100);
448 return true;
451 void
452 uct_dumpbook(struct engine *e, struct board *b, enum stone color)
454 struct tree *t = tree_init(b, color);
455 tree_load(t, b);
456 tree_dump(t, 0);
457 tree_done(t);
461 struct uct *
462 uct_state_init(char *arg, struct board *b)
464 struct uct *u = calloc(1, sizeof(struct uct));
466 u->debug_level = 1;
467 u->games = MC_GAMES;
468 u->gamelen = MC_GAMELEN;
469 u->expand_p = 2;
470 u->dumpthres = 1000;
471 u->playout_amaf = true;
472 u->playout_amaf_nakade = false;
473 u->amaf_prior = false;
475 if (board_size(b) - 2 >= 19)
476 u->dynkomi = 200;
477 u->dynkomi_mask = S_BLACK;
479 u->thread_model = TM_TREEVL;
480 u->parallel_tree = true;
481 u->virtual_loss = true;
483 u->val_scale = 0.02; u->val_points = 20;
485 if (arg) {
486 char *optspec, *next = arg;
487 while (*next) {
488 optspec = next;
489 next += strcspn(next, ",");
490 if (*next) { *next++ = 0; } else { *next = 0; }
492 char *optname = optspec;
493 char *optval = strchr(optspec, '=');
494 if (optval) *optval++ = 0;
496 if (!strcasecmp(optname, "debug")) {
497 if (optval)
498 u->debug_level = atoi(optval);
499 else
500 u->debug_level++;
501 } else if (!strcasecmp(optname, "games") && optval) {
502 u->games = atoi(optval);
503 } else if (!strcasecmp(optname, "gamelen") && optval) {
504 u->gamelen = atoi(optval);
505 } else if (!strcasecmp(optname, "expand_p") && optval) {
506 u->expand_p = atoi(optval);
507 } else if (!strcasecmp(optname, "dumpthres") && optval) {
508 u->dumpthres = atoi(optval);
509 } else if (!strcasecmp(optname, "playout_amaf")) {
510 /* Whether to include random playout moves in
511 * AMAF as well. (Otherwise, only tree moves
512 * are included in AMAF. Of course makes sense
513 * only in connection with an AMAF policy.) */
514 /* with-without: 55.5% (+-4.1) */
515 if (optval && *optval == '0')
516 u->playout_amaf = false;
517 else
518 u->playout_amaf = true;
519 } else if (!strcasecmp(optname, "playout_amaf_nakade")) {
520 /* Whether to include nakade moves from playouts
521 * in the AMAF statistics; this tends to nullify
522 * the playout_amaf effect by adding too much
523 * noise. */
524 if (optval && *optval == '0')
525 u->playout_amaf_nakade = false;
526 else
527 u->playout_amaf_nakade = true;
528 } else if (!strcasecmp(optname, "playout_amaf_cutoff") && optval) {
529 /* Keep only first N% of playout stage AMAF
530 * information. */
531 u->playout_amaf_cutoff = atoi(optval);
532 } else if ((!strcasecmp(optname, "policy") || !strcasecmp(optname, "random_policy")) && optval) {
533 char *policyarg = strchr(optval, ':');
534 struct uct_policy **p = !strcasecmp(optname, "policy") ? &u->policy : &u->random_policy;
535 if (policyarg)
536 *policyarg++ = 0;
537 if (!strcasecmp(optval, "ucb1")) {
538 *p = policy_ucb1_init(u, policyarg);
539 } else if (!strcasecmp(optval, "ucb1amaf")) {
540 *p = policy_ucb1amaf_init(u, policyarg);
541 } else {
542 fprintf(stderr, "UCT: Invalid tree policy %s\n", optval);
543 exit(1);
545 } else if (!strcasecmp(optname, "playout") && optval) {
546 char *playoutarg = strchr(optval, ':');
547 if (playoutarg)
548 *playoutarg++ = 0;
549 if (!strcasecmp(optval, "moggy")) {
550 u->playout = playout_moggy_init(playoutarg);
551 } else if (!strcasecmp(optval, "light")) {
552 u->playout = playout_light_init(playoutarg);
553 } else if (!strcasecmp(optval, "elo")) {
554 u->playout = playout_elo_init(playoutarg);
555 } else {
556 fprintf(stderr, "UCT: Invalid playout policy %s\n", optval);
557 exit(1);
559 } else if (!strcasecmp(optname, "prior") && optval) {
560 u->prior = uct_prior_init(optval);
561 } else if (!strcasecmp(optname, "amaf_prior") && optval) {
562 u->amaf_prior = atoi(optval);
563 } else if (!strcasecmp(optname, "threads") && optval) {
564 u->threads = atoi(optval);
565 } else if (!strcasecmp(optname, "thread_model") && optval) {
566 if (!strcasecmp(optval, "none")) {
567 /* Turn off multi-threaded reading. */
568 u->thread_model = TM_NONE;
569 #ifdef ROOT_PARALLEL
570 } else if (!strcasecmp(optval, "root")) {
571 /* Root parallelization - each thread
572 * does independent search, trees are
573 * merged at the end. */
574 u->thread_model = TM_ROOT;
575 u->parallel_tree = false;
576 u->virtual_loss = false;
577 #endif
578 } else if (!strcasecmp(optval, "tree")) {
579 /* Tree parallelization - all threads
580 * grind on the same tree. */
581 u->thread_model = TM_TREE;
582 u->parallel_tree = true;
583 u->virtual_loss = false;
584 } else if (!strcasecmp(optval, "treevl")) {
585 /* Tree parallelization, but also
586 * with virtual losses - this discou-
587 * rages most threads choosing the
588 * same tree branches to read. */
589 u->thread_model = TM_TREEVL;
590 u->parallel_tree = true;
591 u->virtual_loss = true;
592 } else {
593 fprintf(stderr, "UCT: Invalid thread model %s\n", optval);
594 exit(1);
596 } else if (!strcasecmp(optname, "force_seed") && optval) {
597 u->force_seed = atoi(optval);
598 } else if (!strcasecmp(optname, "no_book")) {
599 u->no_book = true;
600 } else if (!strcasecmp(optname, "dynkomi")) {
601 /* Dynamic komi in handicap game; linearly
602 * decreases to basic settings until move
603 * #optval. */
604 u->dynkomi = optval ? atoi(optval) : 150;
605 } else if (!strcasecmp(optname, "dynkomi_mask") && optval) {
606 /* Bitmask of colors the player must be
607 * for dynkomi be applied; you may want
608 * to use dynkomi_mask=3 to allow dynkomi
609 * even in games where Pachi is white. */
610 u->dynkomi_mask = atoi(optval);
611 } else if (!strcasecmp(optname, "val_scale") && optval) {
612 /* How much of the game result value should be
613 * influenced by win size. Zero means it isn't. */
614 u->val_scale = atof(optval);
615 } else if (!strcasecmp(optname, "val_points") && optval) {
616 /* Maximum size of win to be scaled into game
617 * result value. Zero means boardsize^2. */
618 u->val_points = atoi(optval) * 2; // result values are doubled
619 } else if (!strcasecmp(optname, "val_extra")) {
620 /* If false, the score coefficient will be simply
621 * added to the value, instead of scaling the result
622 * coefficient because of it. */
623 u->val_extra = !optval || atoi(optval);
624 } else if (!strcasecmp(optname, "root_heuristic") && optval) {
625 /* Whether to bias exploration by root node values
626 * (must be supported by the used policy).
627 * 0: Don't.
628 * 1: Do, value = result.
629 * Try to temper the result:
630 * 2: Do, value = 0.5+(result-expected)/2.
631 * 3: Do, value = 0.5+bzz((result-expected)^2). */
632 u->root_heuristic = atoi(optval);
633 } else if (!strcasecmp(optname, "pass_all_alive")) {
634 /* Whether to consider all stones alive at the game
635 * end instead of marking dead groupd. */
636 u->pass_all_alive = !optval || atoi(optval);
637 } else if (!strcasecmp(optname, "random_policy_chance") && optval) {
638 /* If specified (N), with probability 1/N, random_policy policy
639 * descend is used instead of main policy descend; useful
640 * if specified policy (e.g. UCB1AMAF) can make unduly biased
641 * choices sometimes, you can fall back to e.g.
642 * random_policy=UCB1. */
643 u->random_policy_chance = atoi(optval);
644 } else if (!strcasecmp(optname, "banner") && optval) {
645 /* Additional banner string. This must come as the
646 * last engine parameter. */
647 if (*next) *--next = ',';
648 u->banner = strdup(optval);
649 break;
650 } else {
651 fprintf(stderr, "uct: Invalid engine argument %s or missing value\n", optname);
652 exit(1);
657 u->resign_ratio = 0.2; /* Resign when most games are lost. */
658 u->loss_threshold = 0.85; /* Stop reading if after at least 5000 playouts this is best value. */
659 if (!u->policy)
660 u->policy = policy_ucb1amaf_init(u, NULL);
661 if (!u->threads) {
662 u->thread_model = TM_NONE;
663 u->parallel_tree = false;
666 if (!!u->random_policy_chance ^ !!u->random_policy) {
667 fprintf(stderr, "uct: Only one of random_policy and random_policy_chance is set\n");
668 exit(1);
671 if (!u->prior)
672 u->prior = uct_prior_init(NULL);
674 if (!u->playout)
675 u->playout = playout_moggy_init(NULL);
676 u->playout->debug_level = u->debug_level;
678 u->ownermap.map = malloc(board_size2(b) * sizeof(u->ownermap.map[0]));
680 /* Some things remain uninitialized for now - the opening book
681 * is not loaded and the tree not set up. */
682 /* This will be initialized in setup_state() at the first move
683 * received/requested. This is because right now we are not aware
684 * about any komi or handicap setup and such. */
686 return u;
689 struct engine *
690 engine_uct_init(char *arg, struct board *b)
692 struct uct *u = uct_state_init(arg, b);
693 struct engine *e = calloc(1, sizeof(struct engine));
694 e->name = "UCT Engine";
695 e->printhook = uct_printhook_ownermap;
696 e->notify_play = uct_notify_play;
697 e->chat = uct_chat;
698 e->genmove = uct_genmove;
699 e->dead_group_list = uct_dead_group_list;
700 e->done = uct_done;
701 e->data = u;
703 const char banner[] = "I'm playing UCT. When I'm losing, I will resign, "
704 "if I think I win, I play until you pass. "
705 "Anyone can send me 'winrate' in private chat to get my assessment of the position.";
706 if (!u->banner) u->banner = "";
707 e->comment = malloc(sizeof(banner) + strlen(u->banner) + 1);
708 sprintf(e->comment, "%s %s", banner, u->banner);
710 return e;