t-unit: display stats at the end
[pachi.git] / gtp.c
blob31bb278bf5b353f755df776f88889418b258b2c3
1 #define DEBUG
2 #include <assert.h>
3 #include <ctype.h>
4 #include <math.h>
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "board.h"
12 #include "debug.h"
13 #include "engine.h"
14 #include "fbook.h"
15 #include "gtp.h"
16 #include "mq.h"
17 #include "uct/uct.h"
18 #include "version.h"
19 #include "timeinfo.h"
20 #include "gogui.h"
22 #define NO_REPLY (-2)
24 /* Sleep 5 seconds after a game ends to give time to kill the program. */
25 #define GAME_OVER_SLEEP 5
27 void
28 gtp_prefix(char prefix, int id)
30 if (id == NO_REPLY) return;
31 if (id >= 0)
32 printf("%c%d ", prefix, id);
33 else
34 printf("%c ", prefix);
37 void
38 gtp_flush(void)
40 putchar('\n');
41 fflush(stdout);
44 void
45 gtp_output(char prefix, int id, va_list params)
47 if (id == NO_REPLY) return;
48 gtp_prefix(prefix, id);
49 char *s;
50 while ((s = va_arg(params, char *))) {
51 fputs(s, stdout);
53 putchar('\n');
54 gtp_flush();
57 void
58 gtp_reply(int id, ...)
60 va_list params;
61 va_start(params, id);
62 gtp_output('=', id, params);
63 va_end(params);
66 void
67 gtp_error(int id, ...)
69 va_list params;
70 va_start(params, id);
71 gtp_output('?', id, params);
72 va_end(params);
75 static void
76 gtp_final_score(struct board *board, struct engine *engine, char *reply, int len)
78 struct move_queue q = { .moves = 0 };
79 if (engine->dead_group_list)
80 engine->dead_group_list(engine, board, &q);
81 floating_t score = board_official_score(board, &q);
82 if (DEBUGL(1))
83 fprintf(stderr, "counted score %.1f\n", score);
84 if (score == 0)
85 snprintf(reply, len, "0");
86 else if (score > 0)
87 snprintf(reply, len, "W+%.1f", score);
88 else
89 snprintf(reply, len, "B+%.1f", -score);
92 /* List of known gtp commands. The internal command pachi-genmoves is not exported,
93 * it should only be used between master and slaves of the distributed engine. */
94 static char *known_commands_base =
95 "protocol_version\n"
96 "echo\n"
97 "name\n"
98 "version\n"
99 "list_commands\n"
100 "known_command\n"
101 "quit\n"
102 "boardsize\n"
103 "clear_board\n"
104 "kgs-game_over\n"
105 "komi\n"
106 "kgs-rules\n"
107 "play\n"
108 "genmove\n"
109 "kgs-genmove_cleanup\n"
110 "set_free_handicap\n"
111 "place_free_handicap\n"
112 "fixed_handicap\n"
113 "final_score\n"
114 "final_status_list\n"
115 "undo\n"
116 "pachi-evaluate\n"
117 "pachi-result\n"
118 "pachi-gentbook\n"
119 "pachi-dumptbook\n"
120 "kgs-chat\n"
121 "time_left\n"
122 "time_settings\n"
123 "kgs-time_settings";
125 static char*
126 known_commands(struct engine *engine)
128 static char *str = 0;
129 if (str)
130 return str;
131 if (strcmp(engine->name, "UCT")) /* Not uct ? */
132 return known_commands_base;
133 /* For now only uct supports gogui-analyze_commands */
134 str = malloc(strlen(known_commands_base) + 32);
135 sprintf(str, "%s\ngogui-analyze_commands", known_commands_base);
136 return str;
139 static char *gogui_analyze_commands =
140 "string/ Final Score/final_score\n"
141 "gfx/gfx Best Moves B/gogui-best_moves b\n"
142 "gfx/gfx Best Moves W/gogui-best_moves w\n"
143 "gfx/gfx Winrates B/gogui-winrates b\n"
144 "gfx/gfx Winrates W/gogui-winrates w\n"
145 "gfx/gfx Owner Map/gogui-owner_map\n"
146 "gfx/Live gfx = Best Moves/gogui-live_gfx best_moves\n"
147 "gfx/Live gfx = Best Sequence/gogui-live_gfx best_seq\n"
148 "gfx/Live gfx = Winrates/gogui-live_gfx winrates\n";
151 char gogui_gfx_buf[5000];
152 enum gogui_reporting gogui_live_gfx = 0;
154 static void
155 gogui_set_live_gfx(struct engine *engine, char *arg)
157 if (!strcmp(arg, "best_moves"))
158 gogui_live_gfx = UR_GOGUI_CAN;
159 if (!strcmp(arg, "best_seq"))
160 gogui_live_gfx = UR_GOGUI_SEQ;
161 if (!strcmp(arg, "winrates"))
162 gogui_live_gfx = UR_GOGUI_WR;
163 engine->live_gfx_hook(engine);
166 static char *
167 gogui_best_moves(struct board *b, struct engine *engine, char *arg, bool winrates)
169 enum stone color = str2stone(arg);
170 assert(color != S_NONE);
171 enum gogui_reporting prev = gogui_live_gfx;
172 gogui_set_live_gfx(engine, (winrates ? "winrates" : "best_moves"));
173 gogui_gfx_buf[0] = 0;
174 engine->best_moves(engine, b, color);
175 gogui_live_gfx = prev;
176 return gogui_gfx_buf;
179 /* XXX Completely unsafe if reply buffer is not big enough */
180 static void
181 gogui_owner_map(struct board *b, struct engine *engine, char *reply)
183 char str2[32];
184 reply[0] = 0;
185 if (!engine->owner_map)
186 return;
188 sprintf(reply, "INFLUENCE");
189 foreach_point(b) {
190 if (board_at(b, c) == S_OFFBOARD)
191 continue;
192 float p = engine->owner_map(engine, b, c);
194 // p = -1 for WHITE, 1 for BLACK absolute ownership of point i
195 if (p < -.8)
196 p = -1.0;
197 else if (p < -.5)
198 p = -0.7;
199 else if (p < -.2)
200 p = -0.4;
201 else if (p < 0.2)
202 p = 0.0;
203 else if (p < 0.5)
204 p = 0.4;
205 else if (p < 0.8)
206 p = 0.7;
207 else
208 p = 1.0;
209 sprintf(str2, " %3s %.1lf", coord2sstr(c, b), p);
210 strcat(reply, str2);
211 } foreach_point_end;
213 strcat(reply, "\nTEXT Score Est: ");
214 gtp_final_score(b, engine, str2, sizeof(str2));
215 strcat(reply, str2);
218 /* Return true if cmd is a valid gtp command. */
219 bool
220 gtp_is_valid(struct engine *e, const char *cmd)
222 if (!cmd || !*cmd) return false;
223 const char *s = strcasestr(known_commands(e), cmd);
224 if (!s) return false;
225 if (s != known_commands(e) && s[-1] != '\n') return false;
227 int len = strlen(cmd);
228 return s[len] == '\0' || s[len] == '\n';
231 /* XXX: THIS IS TOTALLY INSECURE!!!!
232 * Even basic input checking is missing. */
234 enum parse_code
235 gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char *buf)
237 #define next_tok(to_) \
238 to_ = next; \
239 next = next + strcspn(next, " \t\r\n"); \
240 if (*next) { \
241 *next = 0; next++; \
242 next += strspn(next, " \t\r\n"); \
245 if (strchr(buf, '#'))
246 *strchr(buf, '#') = 0;
248 char *cmd, *next = buf;
249 next_tok(cmd);
251 int id = -1;
252 if (isdigit(*cmd)) {
253 id = atoi(cmd);
254 next_tok(cmd);
257 if (!*cmd)
258 return P_OK;
260 if (!strcasecmp(cmd, "protocol_version")) {
261 gtp_reply(id, "2", NULL);
262 return P_OK;
264 } else if (!strcasecmp(cmd, "name")) {
265 /* KGS hack */
266 gtp_reply(id, "Pachi ", engine->name, NULL);
267 return P_OK;
269 } else if (!strcasecmp(cmd, "echo")) {
270 gtp_reply(id, next, NULL);
271 return P_OK;
273 } else if (!strcasecmp(cmd, "version")) {
274 gtp_reply(id, PACHI_VERSION, ": ", engine->comment, " Have a nice game!", NULL);
275 return P_OK;
277 } else if (!strcasecmp(cmd, "list_commands")) {
278 gtp_reply(id, known_commands(engine), NULL);
279 return P_OK;
281 } else if (!strcasecmp(cmd, "known_command")) {
282 char *arg;
283 next_tok(arg);
284 if (gtp_is_valid(engine, arg)) {
285 gtp_reply(id, "true", NULL);
286 } else {
287 gtp_reply(id, "false", NULL);
289 return P_OK;
292 if (engine->notify && gtp_is_valid(engine, cmd)) {
293 char *reply;
294 enum parse_code c = engine->notify(engine, board, id, cmd, next, &reply);
295 if (c == P_NOREPLY) {
296 id = NO_REPLY;
297 } else if (c == P_DONE_OK) {
298 gtp_reply(id, reply, NULL);
299 return P_OK;
300 } else if (c == P_DONE_ERROR) {
301 gtp_error(id, reply, NULL);
302 /* This is an internal error for the engine, but
303 * it is still OK from main's point of view. */
304 return P_OK;
305 } else if (c != P_OK) {
306 return c;
310 if (!strcasecmp(cmd, "quit")) {
311 gtp_reply(id, NULL);
312 exit(0);
314 } else if (!strcasecmp(cmd, "boardsize")) {
315 char *arg;
316 next_tok(arg);
317 int size = atoi(arg);
318 if (size < 1 || size > BOARD_MAX_SIZE) {
319 gtp_error(id, "illegal board size", NULL);
320 return P_OK;
322 board_resize(board, size);
323 board_clear(board);
324 gtp_reply(id, NULL);
325 return P_ENGINE_RESET;
327 } else if (!strcasecmp(cmd, "clear_board")) {
328 board_clear(board);
329 if (DEBUGL(3) && debug_boardprint)
330 board_print(board, stderr);
331 gtp_reply(id, NULL);
332 return P_ENGINE_RESET;
334 } else if (!strcasecmp(cmd, "kgs-game_over")) {
335 /* The game may not be really over, just adjourned.
336 * Do not clear the board to avoid illegal moves
337 * if the game is resumed immediately after. KGS
338 * may start directly with genmove on resumption. */
339 if (DEBUGL(1)) {
340 fprintf(stderr, "game is over\n");
341 fflush(stderr);
343 if (engine->stop)
344 engine->stop(engine);
345 /* Sleep before replying, so that kgs doesn't
346 * start another game immediately. */
347 sleep(GAME_OVER_SLEEP);
348 gtp_reply(id, NULL);
350 } else if (!strcasecmp(cmd, "komi")) {
351 char *arg;
352 next_tok(arg);
353 sscanf(arg, PRIfloating, &board->komi);
355 if (DEBUGL(3) && debug_boardprint)
356 board_print(board, stderr);
357 gtp_reply(id, NULL);
359 } else if (!strcasecmp(cmd, "kgs-rules")) {
360 char *arg;
361 next_tok(arg);
362 if (!board_set_rules(board, arg)) {
363 gtp_error(id, "unknown rules", NULL);
364 return P_OK;
366 gtp_reply(id, NULL);
368 } else if (!strcasecmp(cmd, "play")) {
369 struct move m;
371 char *arg;
372 next_tok(arg);
373 m.color = str2stone(arg);
374 next_tok(arg);
375 coord_t *c = str2coord(arg, board_size(board));
376 m.coord = *c; coord_done(c);
377 next_tok(arg);
378 char *enginearg = arg;
379 char *reply = NULL;
381 if (DEBUGL(5))
382 fprintf(stderr, "got move %d,%d,%d\n", m.color, coord_x(m.coord, board), coord_y(m.coord, board));
384 // This is where kgs starts the timer, not at genmove!
385 time_start_timer(&ti[stone_other(m.color)]);
387 if (engine->notify_play)
388 reply = engine->notify_play(engine, board, &m, enginearg);
389 if (board_play(board, &m) < 0) {
390 if (DEBUGL(0)) {
391 fprintf(stderr, "! ILLEGAL MOVE %d,%d,%d\n", m.color, coord_x(m.coord, board), coord_y(m.coord, board));
392 board_print(board, stderr);
394 gtp_error(id, "illegal move", NULL);
395 } else {
396 if (DEBUGL(4) && debug_boardprint)
397 board_print_custom(board, stderr, engine->printhook);
398 gtp_reply(id, reply, NULL);
401 } else if (!strcasecmp(cmd, "genmove") || !strcasecmp(cmd, "kgs-genmove_cleanup")) {
402 char *arg;
403 next_tok(arg);
404 enum stone color = str2stone(arg);
405 coord_t *c = NULL;
406 if (DEBUGL(2) && debug_boardprint)
407 board_print_custom(board, stderr, engine->printhook);
409 if (!ti[color].len.t.timer_start) {
410 /* First game move. */
411 time_start_timer(&ti[color]);
414 coord_t cf = pass;
415 if (board->fbook)
416 cf = fbook_check(board);
417 if (!is_pass(cf)) {
418 c = coord_copy(cf);
419 } else {
420 c = engine->genmove(engine, board, &ti[color], color, !strcasecmp(cmd, "kgs-genmove_cleanup"));
422 struct move m = { *c, color };
423 if (board_play(board, &m) < 0) {
424 fprintf(stderr, "Attempted to generate an illegal move: [%s, %s]\n", coord2sstr(m.coord, board), stone2str(m.color));
425 abort();
427 char *str = coord2str(*c, board);
428 if (DEBUGL(4))
429 fprintf(stderr, "playing move %s\n", str);
430 if (DEBUGL(1) && debug_boardprint) {
431 board_print_custom(board, stderr, engine->printhook);
433 gtp_reply(id, str, NULL);
434 free(str); coord_done(c);
436 /* Account for spent time. If our GTP peer keeps our clock, this will
437 * be overriden by next time_left GTP command properly. */
438 /* (XXX: Except if we pass to byoyomi and the peer doesn't, but that
439 * should be absolutely rare situation and we will just spend a little
440 * less time than we could on next few moves.) */
441 if (ti[color].period != TT_NULL && ti[color].dim == TD_WALLTIME)
442 time_sub(&ti[color], time_now() - ti[color].len.t.timer_start, true);
444 } else if (!strcasecmp(cmd, "pachi-genmoves") || !strcasecmp(cmd, "pachi-genmoves_cleanup")) {
445 char *arg;
446 next_tok(arg);
447 enum stone color = str2stone(arg);
448 void *stats;
449 int stats_size;
451 char *reply = engine->genmoves(engine, board, &ti[color], color, next,
452 !strcasecmp(cmd, "pachi-genmoves_cleanup"),
453 &stats, &stats_size);
454 if (!reply) {
455 gtp_error(id, "genmoves error", NULL);
456 return P_OK;
458 if (DEBUGL(3))
459 fprintf(stderr, "proposing moves %s\n", reply);
460 if (DEBUGL(4) && debug_boardprint)
461 board_print_custom(board, stderr, engine->printhook);
462 gtp_reply(id, reply, NULL);
463 if (stats_size > 0) {
464 double start = time_now();
465 fwrite(stats, 1, stats_size, stdout);
466 fflush(stdout);
467 if (DEBUGVV(2))
468 fprintf(stderr, "sent reply %d bytes in %.4fms\n",
469 stats_size, (time_now() - start)*1000);
472 } else if (!strcasecmp(cmd, "set_free_handicap")) {
473 struct move m;
474 m.color = S_BLACK;
476 char *arg;
477 next_tok(arg);
478 do {
479 coord_t *c = str2coord(arg, board_size(board));
480 m.coord = *c; coord_done(c);
481 if (DEBUGL(4))
482 fprintf(stderr, "setting handicap %d,%d\n", coord_x(m.coord, board), coord_y(m.coord, board));
484 if (board_play(board, &m) < 0) {
485 if (DEBUGL(0))
486 fprintf(stderr, "! ILLEGAL MOVE %d,%d,%d\n", m.color, coord_x(m.coord, board), coord_y(m.coord, board));
487 gtp_error(id, "illegal move", NULL);
489 board->handicap++;
490 next_tok(arg);
491 } while (*arg);
492 if (DEBUGL(1) && debug_boardprint)
493 board_print(board, stderr);
494 gtp_reply(id, NULL);
496 /* TODO: Engine should choose free handicap; however, it tends to take
497 * overly long to think it all out, and unless it's clever its
498 * handicap stones won't be of much help. ;-) */
499 } else if (!strcasecmp(cmd, "place_free_handicap")
500 || !strcasecmp(cmd, "fixed_handicap")) {
501 char *arg;
502 next_tok(arg);
503 int stones = atoi(arg);
505 gtp_prefix('=', id);
506 board_handicap(board, stones, id == NO_REPLY ? NULL : stdout);
507 if (DEBUGL(1) && debug_boardprint)
508 board_print(board, stderr);
509 if (id == NO_REPLY) return P_OK;
510 putchar('\n');
511 gtp_flush();
513 } else if (!strcasecmp(cmd, "final_score")) {
514 char str[64];
515 gtp_final_score(board, engine, str, sizeof(str));
516 gtp_reply(id, str, NULL);
518 /* XXX: This is a huge hack. */
519 } else if (!strcasecmp(cmd, "final_status_list")) {
520 if (id == NO_REPLY) return P_OK;
521 char *arg;
522 next_tok(arg);
523 struct move_queue q = { .moves = 0 };
524 if (engine->dead_group_list)
525 engine->dead_group_list(engine, board, &q);
526 /* else we return empty list - i.e. engine not supporting
527 * this assumes all stones alive at the game end. */
528 if (!strcasecmp(arg, "dead")) {
529 gtp_prefix('=', id);
530 for (unsigned int i = 0; i < q.moves; i++) {
531 foreach_in_group(board, q.move[i]) {
532 printf("%s ", coord2sstr(c, board));
533 } foreach_in_group_end;
534 putchar('\n');
536 if (!q.moves)
537 putchar('\n');
538 gtp_flush();
539 } else if (!strcasecmp(arg, "seki") || !strcasecmp(arg, "alive")) {
540 gtp_prefix('=', id);
541 bool printed_group = false;
542 foreach_point(board) { // foreach_group, effectively
543 group_t g = group_at(board, c);
544 if (!g || g != c) continue;
546 for (unsigned int i = 0; i < q.moves; i++) {
547 if (q.move[i] == g)
548 goto next_group;
550 foreach_in_group(board, g) {
551 printf("%s ", coord2sstr(c, board));
552 } foreach_in_group_end;
553 putchar('\n');
554 printed_group = true;
555 next_group:;
556 } foreach_point_end;
557 if (!printed_group)
558 putchar('\n');
559 gtp_flush();
560 } else {
561 gtp_error(id, "illegal status specifier", NULL);
564 } else if (!strcasecmp(cmd, "undo")) {
565 if (board_undo(board) < 0) {
566 if (DEBUGL(1)) {
567 fprintf(stderr, "undo on non-pass move %s\n", coord2sstr(board->last_move.coord, board));
568 board_print(board, stderr);
570 gtp_error(id, "cannot undo", NULL);
571 return P_OK;
573 char *reply = NULL;
574 if (engine->undo)
575 reply = engine->undo(engine, board);
576 if (DEBUGL(3) && debug_boardprint)
577 board_print(board, stderr);
578 gtp_reply(id, reply, NULL);
580 /* Custom commands for handling the tree opening tbook */
581 } else if (!strcasecmp(cmd, "pachi-gentbook")) {
582 /* Board must be initialized properly, as if for genmove;
583 * makes sense only as 'uct_gentbook b'. */
584 char *arg;
585 next_tok(arg);
586 enum stone color = str2stone(arg);
587 if (uct_gentbook(engine, board, &ti[color], color))
588 gtp_reply(id, NULL);
589 else
590 gtp_error(id, "error generating tbook", NULL);
592 } else if (!strcasecmp(cmd, "pachi-dumptbook")) {
593 char *arg;
594 next_tok(arg);
595 enum stone color = str2stone(arg);
596 uct_dumptbook(engine, board, color);
597 gtp_reply(id, NULL);
599 } else if (!strcasecmp(cmd, "pachi-evaluate")) {
600 char *arg;
601 next_tok(arg);
602 enum stone color = str2stone(arg);
604 if (!engine->evaluate) {
605 gtp_error(id, "pachi-evaluate not supported by engine", NULL);
606 } else {
607 gtp_prefix('=', id);
608 floating_t vals[board->flen];
609 engine->evaluate(engine, board, &ti[color], vals, color);
610 for (int i = 0; i < board->flen; i++) {
611 if (!board_coord_in_symmetry(board, board->f[i])
612 || isnan(vals[i]) || vals[i] < 0.001)
613 continue;
614 printf("%s %.3f\n", coord2sstr(board->f[i], board), (double) vals[i]);
616 gtp_flush();
619 } else if (!strcasecmp(cmd, "pachi-result")) {
620 /* More detailed result of the last genmove. */
621 /* For UCT, the output format is: = color move playouts winrate dynkomi */
622 char *reply = NULL;
623 if (engine->result)
624 reply = engine->result(engine, board);
625 if (reply)
626 gtp_reply(id, reply, NULL);
627 else
628 gtp_error(id, "unknown pachi-result command", NULL);
630 } else if (!strcasecmp(cmd, "kgs-chat")) {
631 char *loc;
632 next_tok(loc);
633 bool opponent = !strcasecmp(loc, "game");
634 char *from;
635 next_tok(from);
636 char *msg = next;
637 msg += strspn(msg, " \n\t");
638 char *end = strchr(msg, '\n');
639 if (end) *end = '\0';
640 char *reply = NULL;
641 if (engine->chat) {
642 reply = engine->chat(engine, board, opponent, from, msg);
644 if (reply)
645 gtp_reply(id, reply, NULL);
646 else
647 gtp_error(id, "unknown kgs-chat command", NULL);
649 } else if (!strcasecmp(cmd, "time_left")) {
650 char *arg;
651 next_tok(arg);
652 enum stone color = str2stone(arg);
653 next_tok(arg);
654 int time = atoi(arg);
655 next_tok(arg);
656 int stones = atoi(arg);
657 if (!ti[color].ignore_gtp) {
658 time_left(&ti[color], time, stones);
659 } else {
660 if (DEBUGL(2)) fprintf(stderr, "ignored time info\n");
663 gtp_reply(id, NULL);
665 } else if (!strcasecmp(cmd, "time_settings") || !strcasecmp(cmd, "kgs-time_settings")) {
666 char *time_system;
667 char *arg;
668 if (!strcasecmp(cmd, "kgs-time_settings")) {
669 next_tok(time_system);
670 } else {
671 time_system = "canadian";
674 int main_time = 0, byoyomi_time = 0, byoyomi_stones = 0, byoyomi_periods = 0;
675 if (!strcasecmp(time_system, "none")) {
676 main_time = -1;
677 } else if (!strcasecmp(time_system, "absolute")) {
678 next_tok(arg);
679 main_time = atoi(arg);
680 } else if (!strcasecmp(time_system, "byoyomi")) {
681 next_tok(arg);
682 main_time = atoi(arg);
683 next_tok(arg);
684 byoyomi_time = atoi(arg);
685 next_tok(arg);
686 byoyomi_periods = atoi(arg);
687 } else if (!strcasecmp(time_system, "canadian")) {
688 next_tok(arg);
689 main_time = atoi(arg);
690 next_tok(arg);
691 byoyomi_time = atoi(arg);
692 next_tok(arg);
693 byoyomi_stones = atoi(arg);
696 if (DEBUGL(1))
697 fprintf(stderr, "time_settings %d %d/%d*%d\n",
698 main_time, byoyomi_time, byoyomi_stones, byoyomi_periods);
699 if (!ti[S_BLACK].ignore_gtp) {
700 time_settings(&ti[S_BLACK], main_time, byoyomi_time, byoyomi_stones, byoyomi_periods);
701 ti[S_WHITE] = ti[S_BLACK];
702 } else {
703 if (DEBUGL(1)) fprintf(stderr, "ignored time info\n");
706 gtp_reply(id, NULL);
708 } else if (!strcasecmp(cmd, "gogui-analyze_commands")) {
709 gtp_reply(id, gogui_analyze_commands, NULL);
710 } else if (!strcasecmp(cmd, "gogui-live_gfx")) {
711 char *arg;
712 next_tok(arg);
713 gogui_set_live_gfx(engine, arg);
714 gtp_reply(id, NULL);
715 } else if (!strcasecmp(cmd, "gogui-owner_map")) {
716 char reply[5000];
717 gogui_owner_map(board, engine, reply);
718 gtp_reply(id, reply, NULL);
719 } else if (!strcasecmp(cmd, "gogui-best_moves")) {
720 char *arg;
721 next_tok(arg);
722 char *reply = gogui_best_moves(board, engine, arg, false);
723 gtp_reply(id, reply, NULL);
724 } else if (!strcasecmp(cmd, "gogui-winrates")) {
725 char *arg;
726 next_tok(arg);
727 char *reply = gogui_best_moves(board, engine, arg, true);
728 gtp_reply(id, reply, NULL);
730 } else {
731 gtp_error(id, "unknown command", NULL);
732 return P_UNKNOWN_COMMAND;
734 return P_OK;
736 #undef next_tok