My Project
xboard.c
Go to the documentation of this file.
1
14#include "bit.h"
15#include "event.h"
16#include "options.h"
17#include "opening.h"
18#include "play.h"
19#include "search.h"
20#include "stats.h"
21#include "util.h"
22#include "ui.h"
23
24#include <stdarg.h>
25
27
28typedef struct {
29 unsigned long long time;
30 unsigned long long n_nodes;
33
38static void xboard_observer(Result *result)
39{
40 spin_lock(result);
41
42 printf("%2d ", result->depth);
43 printf("%4d ", 100 * result->score);
44 printf("%6lld ", result->time / 10);
45 printf("%10lld ", result->n_nodes);
46 if (result->selectivity < 5) printf("@%2d%% ", selectivity_table[result->selectivity].percent);
47 if (result->book_move) putchar('(');
48 line_print(result->pv, -200, " ", stdout);
49 if (result->book_move) putchar(')');
50 putchar('\n');
51 fflush(stdout);
52
54 fprintf(xboard_log->f, "edax> %2d ", result->depth);
55 fprintf(xboard_log->f, "%4d ", 100 * result->score);
56 fprintf(xboard_log->f, "%6lld ", result->time / 10);
57 fprintf(xboard_log->f, "%10lld ", result->n_nodes);
58 if (result->selectivity < 5) fprintf(xboard_log->f, "@%2d%% ", selectivity_table[result->selectivity].percent);
59 if (result->book_move) fputc('(', xboard_log->f);
60 line_print(result->pv, -200, " ", xboard_log->f);
61 if (result->book_move) fputc(')', xboard_log->f);
62 putc('\n', xboard_log->f);
63 fflush(xboard_log->f);
64 }
65 spin_unlock(result);
66}
67
73{
74 Play *play = ui->play;
75 Search *search = play->search;
76
77 play_init(play, ui->book);
78 play->initial_player = board_from_FEN(play->initial_board, "8/8/8/3Pp3/3pP3/8/8/8 w - - 0 1");
79 play_new(play);
80 search->options.header = NULL;
81 search->options.separator = NULL;
82 ui->book->search = search;
84 search->id = 1;
86 options.level = 60;
87 play->type = ui->type;
88 play->ponder->verbose = true;
89
91}
92
98{
100 book_free(ui->book);
101 play_free(ui->play);
103}
104
110static void xboard_error(const char *format, ...)
111{
112 va_list args;
113
114 fprintf(stderr, "Error ");
115 va_start(args, format);
116 vfprintf(stderr, format, args);
117 va_end(args);
118 putc('\n', stderr);
119 fflush(stderr);
120
121 if (log_is_open(xboard_log)) {
122 fprintf(xboard_log->f, "error> \"");
123 va_start(args, format);
124 vfprintf(xboard_log->f, format, args);
125 va_end(args);
126 fprintf(xboard_log->f, "\"\n");
127 fflush(xboard_log->f);
128 }
129}
130
136static void xboard_send(const char *format, ...)
137{
138 va_list args;
139
140 va_start(args, format);
141 vprintf(format, args);
142 va_end(args);
143 fflush(stdout);
144
145 if (log_is_open(xboard_log)) {
146 fprintf(xboard_log->f, "edax> ");
147 va_start(args, format);
148 vfprintf(xboard_log->f, format, args);
149 va_end(args);
150 fflush(xboard_log->f);
151 }
152}
153
154static void xboard_setup(Play *play)
155{
156 char fen[120];
157
158 xboard_send("setup (P.....p.....) %s\n", board_to_FEN(play->board, play->player, fen));
159}
160
166static void xboard_move(const int x)
167{
168 if (x == PASS) printf("move @@@@\n");
169 else {
170 printf("move P@");
171 move_print(x, 1, stdout);
172 putchar('\n');
173 }
174 fflush(stdout);
175 if (log_is_open(xboard_log)) {
176 if (x == PASS) printf("edax> move @@@@\n");
177 else {
178 fprintf(xboard_log->f, "edax> move P@");
179 move_print(x, 1, xboard_log->f);
180 fputc('\n', xboard_log->f);
181 }
182 fflush(xboard_log->f);
183 }
184}
185
191static void xboard_hint(Play *play)
192{
193 const int x = search_guess(play->search, play->board);
194
195 if (x == NOMOVE) return;
196
197 if (x == PASS) printf("Hint:@@@@\n");
198 else {
199 printf("Hint:P@");
200 move_print(x, 1, stdout);
201 putchar('\n');
202 fflush(stdout);
203 }
204 if (log_is_open(xboard_log)) {
205 if (x == PASS) printf("edax> Hint:@@@@\n");
206 else {
207 fprintf(xboard_log->f, "edax> Hint:P@");
208 move_print(x, 1, xboard_log->f);
209 fputc('\n', xboard_log->f);
210 }
211 fflush(xboard_log->f);
212 }
213}
214
220static void xboard_book(Play *play) {
221 Board *board = play->board;
222 Book *book = play->book;
223 MoveList movelist[1];
224 Move *move;
225
226 if (book_get_moves(book, board, movelist)) {
227 printf("\tBook:");
228 foreach_move(move, movelist) {
229 printf(" P@"); move_print(move->x, 1, stdout);
230 printf(":%d", move->score * 100);
231 }
232 putchar('\n');
233 fflush(stdout);
234 if (log_is_open(xboard_log)) {
235 fprintf(xboard_log->f, "edax> Book:");
236 foreach_move(move, movelist) {
237 fprintf(xboard_log->f, " P@"); move_print(move->x, 1, xboard_log->f);
238 fprintf(xboard_log->f, ":%d", move->score * 100);
239 }
240 putc('\n', xboard_log->f);
241 fflush(xboard_log->f);
242 }
243 }
244}
245
251static void xboard_check_game_over(Play *play)
252{
253 int n_discs[2];
254 const Board *board = play->board;
255 const char *(color[2]) = {"Black", "White"};
256 const int player = WHITE; // !!!!
257 const int opponent = !player;
258
259 if (play_is_game_over(play)) {
260 n_discs[play->player] = bit_count(board->player);
261 n_discs[!play->player] = bit_count(board->opponent);
262 if (n_discs[player] > n_discs[opponent]) xboard_send("1-0 {%s wins %d-%d}\n", color[player], n_discs[player], n_discs[opponent]);
263 else if (n_discs[player] < n_discs[opponent]) xboard_send("0-1 {%s wins %d-%d}\n", color[opponent], n_discs[opponent], n_discs[player]);
264 else xboard_send("1/2-1/2 {Draw %d-%d}\n", n_discs[player], n_discs[opponent]);
265 }
266}
267
271static inline int hash_size(int n)
272{
273 unsigned long long s = sizeof (Hash) << n;
274 return ((s << 1) + (s >> 4) + sizeof (HashTable) * 3) >> 20;
275}
276
283static void xboard_go(UI *ui, XBoardStats *stats)
284{
285 Play *play = ui->play;
286 Search *search = play->search;
287 Result *result = search->result;
288
289 play_go(play, true);
291 play_ponder(play);
293
294 stats->time += result->time;
295 stats->n_nodes += result->n_nodes;
296
297 if (log_is_open(xboard_log)) {
298 if (search->stop == STOP_TIMEOUT) fprintf(xboard_log->f, "edax search> stop on time-out\n");
299 else if (search->stop == STOP_ON_DEMAND) fprintf(xboard_log->f, "edax search> stop on user demand\n");
300 else if (search->stop == STOP_PONDERING) fprintf(xboard_log->f, "edax search> BUG: stop pondering ???\n");
301 else if (search->stop == STOP_END) fprintf(xboard_log->f, "edax search> search completed!\n");
302 else fprintf(xboard_log->f, "edax search> BUG: search stopped for no reason ???\n");
303 fprintf(xboard_log->f, "edax search> time spent = %.2f; depth reached = %d@%d%%; nodes = %lld\n",
304 0.001 * result->time, result->depth, selectivity_table[result->selectivity].percent, result->n_nodes);
305 fprintf(xboard_log->f, "edax search> best score = %d; pv = ", result->score);
306 line_print(result->pv, 100, NULL, xboard_log->f);
307 putc('\n', xboard_log->f);
308 fflush(xboard_log->f);
309 }
310}
311
312
322{
323 while (play->state == IS_ANALYZING) {
324 log_print(xboard_log, "edax (analyze)> stop\n");
326 relax(10);
327 }
328
329 if (play->ponder->launched) {
330 thread_join(play->ponder->thread);
331 play->ponder->launched = false;
332 log_print(xboard_log, "edax (analyze)> stopped\n");
333 }
334}
335
344static void xboard_analyze(Play *play)
345{
348
349 if (play_is_game_over(play)) return;
350 if (play->state == IS_WAITING) {
351 play->ponder->board->player = play->ponder->board->opponent = 0;
352 play->state = IS_ANALYZING;
353 search_cleanup(play->search);
354 log_print(xboard_log, "edax (analyze)> start\n");
355 thread_create2(&play->ponder->thread, play_ponder_run, play); // modified for iOS by lavox. 2018/1/16
356 play->ponder->launched = true;
357 }
358}
359
367static void xboard_loop_analyze(UI *ui)
368{
369 Play *play = ui->play;
370 char *cmd = NULL, *param = NULL;
371 Search *search = play->search;
372
374 xboard_analyze(play);
375
376 for (;;) {
377 errno = 0;
378
379 ui_event_wait(ui, &cmd, &param);
380 log_print(xboard_log, "xboard (analyze)> %s %s\n", cmd, param);
381
382 if (strcmp(cmd, ".") == 0) {
383 spin_lock(search->result);
384 xboard_send("stat01: %d %lld %d %d %d\n",
385 search_time(search) / 10, search_count_nodes(search), search->depth, search->result->n_moves_left, search->result->n_moves);
386 spin_unlock(search->result);
387
388 } else if (strcmp(cmd, "hint") == 0) {
389 xboard_hint(play);
390
391 } else if (strcmp(cmd, "bk") == 0) {
392 xboard_book(play);
393
394 } else if (strcmp(cmd, "new") == 0) {
396 play_new(play);
397 xboard_analyze(play);
398
399 } else if (strcmp(cmd, "undo") == 0) {
401 play_undo(play);
402 xboard_analyze(play);
403
404 } else if ((strcmp(cmd, "setboard") == 0)) {
406 play_set_board_from_FEN(play, param);
407 if (play->initial_player == EMPTY) xboard_error("(bad FEN): %s\n", param);
408 xboard_analyze(play);
409
410 } else if (strcmp(cmd, "exit") == 0) {
412 free(cmd); free(param);
413 ui_loop_xboard(ui);
414 return;
415
416 } else if (strcmp(cmd, "quit") == 0) {
418 free(cmd); free(param);
419 return;
420
421 } else {
423 if (play_user_move(play, cmd)) {
424
425 /* illegal cmd/move */
426 } else if (play_is_game_over(play) && strcmp(cmd, "@@@@") == 0) {
427 // Tolerate a pass when the game is over...
428 } else {
429 xboard_send("Illegal move: %s %s\n", cmd, param);
430 }
431 xboard_analyze(play);
432 }
433 }
434}
435
441{
442 char *cmd = NULL, *param = NULL;
443 Play *play = ui->play;
444 bool alien_variant = false;
445 XBoardStats stats = {0, 0, 0};
446 int edax_turn = EMPTY;
447 int last_edax_turn = !play->player;
448 const char *(color[2]) = {"black", "white"};
449
450 // loop forever
451 for (;;) {
452 errno = 0;
453
454 if (!ui_event_exist(ui) && !play_is_game_over(play) && (edax_turn == play->player)) {
455 log_print(xboard_log, "edax (auto_play)> turn = %s\n", color[edax_turn]);
456 xboard_go(ui, &stats);
457
458 // proceed by reading a command
459 } else {
460
461 ui_event_wait(ui, &cmd, &param);
462 log_print(xboard_log, "xboard> %s %s\n", cmd, param);
463
464 if (cmd == NULL) {
465 xboard_error("(unexpected null command)");
466 continue;
467 }
468
469 // skip empty lines or commented lines
470 if (*cmd == '\0' || *cmd == '#') {
471
472 // xboard
473 } else if (strcmp(cmd, "xboard") == 0) {
474
475 // protover 2
476 } else if (strcmp(cmd, "protover") == 0) {
477 int version = string_to_int(param, 1);
478 if (version >= 2) {
479 xboard_send("feature "
480 "setboard=1 "
481 "playother=1 "
482 "ping=1 "
483 "draw=0 "
484 "sigint=0 "
485 "sigterm=0 "
486 "analyze=1 "
487 "myname=\"%s\" "
488 "variants=\"reversi\" "
489 "colors=0 "
490 "nps=1 "
491 "memory=1 "
492 "smp=1 "
493 "done=1\n", options.name);
494 }
495
496 // accepted features
497 } else if (strcmp(cmd, "accepted") == 0) {
498
499 // accepted features
500 } else if (strcmp(cmd, "debug") == 0) {
501 play_print(play, stdout);
502
503 // rejected features
504 } else if (strcmp(cmd, "rejected") == 0) {
505 char feature[16], *value;
506 value = parse_word(param, feature, 15);
507 // fatal error if reversi variant is rejected
508 if (strcmp(feature, "variants") == 0 && strcmp(value, "reversi") == 0) {
509 free(cmd), free(param);
510 xboard_error("(Reversi only is supported)");
511 return;
512 }
513
514 // new
515 } else if (strcmp(cmd, "new") == 0 ) {
516 options.level = 60;
517 play->initial_player = board_from_FEN(play->initial_board, "8/8/8/3Pp3/3pP3/8/8/8 w - - 0 1");
518 play_new(play);
519 edax_turn = !play->player;
520 if (alien_variant) xboard_setup(play);
521
522 // variant
523 } else if (strcmp(cmd, "variant") == 0 ) {
524 string_to_lowercase(param);
525 if (strcmp(param, "alien") == 0) {
526 alien_variant = true;
527 } else if (strcmp(param, "reversi") == 0) {
528 alien_variant = false;
529 } else {
530 xboard_error("(Unsupported variant) '%s'", param);
531 }
532 xboard_setup(play);
533
534 // quit
535 } else if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "eof") == 0 || strcmp(cmd, "q") == 0) {
536 xboard_send("%d games played in %.2f s. %llu nodes searched\n", stats.n_games, 0.001 * stats.time, stats.n_nodes);
537 free(cmd); free(param);
539 return;
540
541 // random command
542 } else if ((strcmp(cmd, "random") == 0)) {
543 // ignored command;
544
545 // random command
546 } else if ((strcmp(cmd, "force") == 0)) {
548 last_edax_turn = edax_turn;
549 edax_turn = EMPTY;
550
551 // go think!
552 } else if (strcmp(cmd, "go") == 0) {
553 edax_turn = play->player;
554 xboard_go(ui, &stats);
555
556 // playother
557 } else if (strcmp(cmd, "playother") == 0) {
558 edax_turn = play->player;
559 play_ponder(play);
560
561 // white turn (obsolete in protocol version 2)
562 } else if (strcmp(cmd, "white") == 0) {
563 xboard_error("(unknown command): %s %s", cmd, param);
564
565 // black turn (obsolete in protocol version 2)
566 } else if (strcmp(cmd, "black") == 0) {
567 xboard_error("(unknown command): %s %s", cmd, param);
568
569 // time control
570 // TODO: enhance all time support
571 } else if (strcmp(cmd, "level") == 0) {
572 int mps, base, inc, m, s;
573 char *next;
574
575 mps = 0; next = parse_int(param, &mps);
576 m = s = 0; next = parse_skip_spaces(parse_int(next, &m));
577 if (*next == ':') next = parse_int(next + 1, &s);
578 base = 60 * m + s;
579 inc = 0; next = parse_int(next, &inc);
580
581 if ((mps == 0 || mps > 30) && inc == 0) {
582 options.time = 1000ull * base ;
584 log_print(xboard_log, "edax setup> time per game = %.2f s.\n", 0.001 * options.time);
585 } else {
586 int t1 = base * 1000ull / mps;
587 int t2 = (base + inc * mps) * 30; // 30 <- 1000ms / 30moves
588 options.time = MIN(t1, t2);
590 log_print(xboard_log, "edax setup> time per move = %.2f s.\n", 0.001 * options.time);
591 }
592
593 // time control
594 } else if (strcmp(cmd, "st") == 0) {
595 options.time = string_to_time(param);
597 log_print(xboard_log, "edax setup> time per move = %.2f s.\n", 0.001 * options.time);
598
599 // depth level
600 } else if (strcmp(cmd, "sd") == 0) {
601 options.level = string_to_int(param, 60);
602 BOUND(options.level, 0, 60, "level");
603 log_print(xboard_log, "edax setup> fixed level = %d\n", options.level);
604
605 // nps
606 } else if ((strcmp(cmd, "nps") == 0)) {
607 options.nps = 0.001 * string_to_real(param, options.nps);
608
609 // time
610 } else if ((strcmp(cmd, "time") == 0)) {
611 int t;
612 t = string_to_int(param, 100);
613 if (t > 6000) t -= 1000; else if (t > 1000) t -= 100; // keep a margin
614 play->time[edax_turn == EMPTY ? last_edax_turn : edax_turn].left = t * 10; // 100% of available time...
615
616 } else if ((strcmp(cmd, "otim") == 0)) {
617 int t;
618 t = string_to_int(param, 100);
619 if (t > 6000) t -= 1000; else if (t > 1000) t -= 100; // keep a margin
620 play->time[edax_turn == EMPTY ? !last_edax_turn : !edax_turn].left = t * 10; // 100% of available time...
621
622 // interrupt thinking
623 } else if (strcmp(cmd, "?") == 0) {
624 // processed in the event loop
625
626 // ping
627 } else if ((strcmp(cmd, "ping") == 0)) {
628 xboard_send("pong %s\n", param);
629
630 // draw
631 } else if ((strcmp(cmd, "draw") == 0)) {
632 // never accept draw... terminating a solved game should take no time
633
634 // result
635 } else if ((strcmp(cmd, "result") == 0)) {
636 ++stats.n_games;
637 if (options.auto_store) {
638 long t = real_clock();
639 play->book->options.verbosity = play->book->search->options.verbosity = 0;
640 log_print(xboard_log, "edax learning>\n");
641 play_store(play);
642 log_print(xboard_log, "edax learning> done in %.2fs\n", 0.001 * (real_clock() - t));
643 }
644
645 // setboard
646 } else if ((strcmp(cmd, "setboard") == 0)) {
647 play_set_board_from_FEN(play, param);
648 if (play->initial_player == EMPTY) xboard_error("(bad FEN): %s\n", param);
650
651 } else if ((strcmp(cmd, "edit") == 0)) {
652 xboard_error("(unknown command): %s %s", cmd, param);
653
654 } else if ((strcmp(cmd, "hint") == 0)) {
655 xboard_hint(play);
656
657 } else if ((strcmp(cmd, "bk") == 0)) {
658 xboard_book(play);
659
660 } else if ((strcmp(cmd, "undo") == 0)) {
661 play_undo(play);
662
663 } else if ((strcmp(cmd, "remove") == 0)) {
664 play_undo(play);
665 play_undo(play);
666
667 } else if ((strcmp(cmd, "hard") == 0)) {
668 options.can_ponder = true;
669 if (edax_turn != play->player) play_ponder(play);
670
671 } else if ((strcmp(cmd, "easy") == 0)) {
672 options.can_ponder = false;
674
675 } else if ((strcmp(cmd, "post") == 0)) {
676 options.verbosity = 2;
677
678 } else if ((strcmp(cmd, "nopost") == 0)) {
679 options.verbosity = 0;
680
681 } else if ((strcmp(cmd, "analyze") == 0)) {
682 free(cmd); free(param);
684 return;
685
686 } else if ((strcmp(cmd, "name") == 0)) {
687 xboard_send("Hello %s!\n", param);
688
689 } else if ((strcmp(cmd, "rating") == 0)) {
690
691 } else if ((strcmp(cmd, "ics") == 0)) {
692
693 } else if ((strcmp(cmd, "computer") == 0)) {
694
695 } else if ((strcmp(cmd, "pause") == 0)) {
696 xboard_error("(unknown command): %s %s", cmd, param);
697
698 } else if ((strcmp(cmd, "resume") == 0)) {
699 xboard_error("(unknown command): %s %s", cmd, param);
700
701 } else if ((strcmp(cmd, "memory") == 0)) {
702 int size = string_to_int(param, 100);
703
705 BOUND(options.hash_table_size, 10, 30, "hash-table-size");
706 log_print(xboard_log, "edax setup> hash table size: 2**%d entries\n", options.hash_table_size);
709
710 } else if ((strcmp(cmd, "cores") == 0)) {
711 options.n_task = string_to_int(param, 1);
712 log_print(xboard_log, "edax setup> cores: %d\n", options.n_task);
713 if (search_count_tasks(play->search) != options.n_task) {
716 }
717
718 } else if ((strcmp(cmd, "egtpath") == 0)) {
719 xboard_error("(unknown command): %s %s", cmd, param);
720
721 } else if ((strcmp(cmd, "option") == 0)) {
722 xboard_error("(unknown command): %s %s", cmd, param);
723
724 // move
725 } else if (strcmp(cmd, "usermove") == 0) {
726 if (!play_user_move(play, param)) {
727 xboard_send("Illegal move %s\n", param);
728 }
730 if (alien_variant) xboard_setup(play);
731
732 } else if (play_user_move(play, cmd)) {
734 if (alien_variant) xboard_setup(play);
735
736 /* illegal cmd/move */
737 } else {
738 if (play_is_game_over(play) && strcmp(cmd, "@@@@") == 0) {
739 // Tolerate a pass when the game is over...
740 } else {
741 xboard_send("Illegal move: %s %s\n", cmd, param);
742 }
743 }
744 }
745 }
746}
DLL_API int bit_count(unsigned long long b)
Count the number of bits set to one in an unsigned long long.
Definition bit.c:72
char * board_to_FEN(const Board *board, const int player, char *string)
print to FEN description.
Definition board.c:1312
int board_from_FEN(Board *board, const char *string)
Set a board from a string description.
Definition board.c:212
void book_free(Book *book)
Free resources used by the opening book.
Definition book.c:1422
void book_save(Book *book, const char *file)
Save an opening book.
Definition book.c:1622
bool book_get_moves(Book *book, const Board *board, MoveList *movelist)
Get a list of moves from the book.
Definition book.c:2360
void book_load(Book *book, const char *file)
Load the opening book.
Definition book.c:1471
@ PASS
Definition const.h:37
@ NOMOVE
Definition const.h:37
@ WHITE
Definition const.h:43
@ EMPTY
Definition const.h:44
@ STOP_ON_DEMAND
Definition const.h:75
@ STOP_TIMEOUT
Definition const.h:74
@ STOP_END
Definition const.h:76
@ STOP_PONDERING
Definition const.h:73
@ IS_WAITING
Definition const.h:100
@ IS_ANALYZING
Definition const.h:102
void version(void)
Print version & copyright.
Definition main.c:27
struct Hash Hash
void line_print(const Line *line, int width, const char *separator, FILE *f)
Print a move sequence.
Definition move.c:610
void move_print(const int x, const int player, FILE *f)
Print out a move.
Definition move.c:110
#define foreach_move(iter, movelist)
Definition move.h:78
Options options
Definition options.c:22
@ EDAX_TIME_PER_GAME
Definition options.h:19
@ EDAX_TIME_PER_MOVE
Definition options.h:20
void play_store(Play *play)
store the game into the opening book
Definition play.c:1175
void play_print(Play *play, FILE *f)
Print the game state.
Definition play.c:1225
void play_set_board_from_FEN(Play *play, const char *board)
Set a new board.
Definition play.c:828
void play_ponder(Play *play)
Ponder.
Definition play.c:729
void play_stop_pondering(Play *play)
Stop pondering.
Definition play.c:749
void play_new(Play *play)
Start a new game.
Definition play.c:62
void play_init(Play *play, Book *book)
Initialization.
Definition play.c:27
bool play_user_move(Play *play, const char *string)
Play a user move.
Definition play.c:909
Move * play_get_last_move(Play *play)
Get the last played move.
Definition play.c:927
void * play_ponder_run(void *v)
do ponderation.
Definition play.c:662
void play_undo(Play *play)
Undo a move.
Definition play.c:779
bool play_is_game_over(Play *play)
Check if game is over.
Definition play.c:190
void play_go(Play *play, const bool update)
Start thinking.
Definition play.c:214
void play_free(Play *play)
Free resources.
Definition play.c:52
Edax play control - header file.
const Selectivity selectivity_table[]
Definition search.c:97
unsigned long long search_count_nodes(Search *search)
Return the number of nodes searched.
Definition search.c:1073
void search_set_task_number(Search *search, const int n)
Change the number of task.
Definition search.c:847
void search_cleanup(Search *search)
Clean-up some search data.
Definition search.c:578
void search_set_observer(Search *search, void(*observer)(Result *))
set observer.
Definition search.c:1095
int search_guess(Search *search, const Board *board)
Guess the bestmove of a given board.
Definition search.c:1369
int search_count_tasks(const Search *search)
Count the number of tasks used in parallel search.
Definition search.c:1324
void search_resize_hashtable(Search *search)
Definition search.c:333
void search_stop_all(Search *search, const Stop stop)
Stop the search.
Definition search.c:1335
long long search_time(Search *search)
Return the time spent by the search.
Definition search.c:1061
void statistics_print(FILE *f)
Print statistics.
Definition stats.c:112
Statistics header.
Definition board.h:26
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
The opening book.
Definition book.h:25
bool need_saving
Definition book.h:47
int verbosity
Definition book.h:36
struct Book::@1 options
Search * search
Definition book.h:49
Definition hash.h:47
LogFile.
Definition util.h:423
FILE * f
Definition util.h:424
Definition move.h:29
Definition move.h:20
int score
Definition move.h:23
int x
Definition move.h:22
PlayType play_type
Definition options.h:42
bool can_ponder
Definition options.h:43
int n_task
Definition options.h:29
int level
Definition options.h:40
char * ui_log_file
Definition options.h:78
long long time
Definition options.h:41
double nps
Definition options.h:50
char * book_file
Definition options.h:59
int hash_table_size
Definition options.h:25
char * name
Definition options.h:81
bool auto_store
Definition options.h:84
int verbosity
Definition options.h:32
Definition play.h:25
int player
Definition play.h:32
bool verbose
Definition play.h:57
Board board[1]
Definition play.h:26
long long left
Definition play.h:42
int initial_player
Definition play.h:33
Board initial_board[1]
Definition play.h:27
Thread thread
Definition play.h:53
bool launched
Definition play.h:56
struct Play::@21 time[2]
Search search[1]
Definition play.h:28
volatile PlayState state
Definition play.h:37
struct Play::@23 ponder[1]
int type
Definition play.h:31
Book * book
Definition play.h:30
Definition search.h:41
bool book_move
Definition search.h:50
unsigned long long n_nodes
Definition search.h:49
int score
Definition search.h:45
long long time
Definition search.h:48
int n_moves_left
Definition search.h:52
int selectivity
Definition search.h:43
Line pv[1]
Definition search.h:47
int depth
Definition search.h:42
int n_moves
Definition search.h:51
Definition search.h:95
const char * separator
Definition search.h:145
Result * result
Definition search.h:151
const char * header
Definition search.h:144
int id
Definition search.h:101
struct Search::@25 options
int verbosity
Definition search.h:142
int depth
Definition search.h:117
volatile Stop stop
Definition search.h:122
int percent
Definition search.h:28
Definition ui.h:31
int type
Definition ui.h:36
Play play[2]
Definition ui.h:32
Book book[1]
Definition ui.h:33
Definition xboard.c:28
int n_games
Definition xboard.c:31
unsigned long long n_nodes
Definition xboard.c:30
unsigned long long time
Definition xboard.c:29
bool ui_event_exist(UI *ui)
ui_event_exist
Definition ui.c:189
void ui_event_wait(UI *ui, char **cmd, char **param)
Wait input.
Definition ui.c:147
User interface header.
char * parse_int(const char *string, int *result)
Parse an integer.
Definition util.c:761
void thread_create2(Thread *thread, void *(*function)(void *), void *data)
Create a thread.
Definition util.c:922
void thread_join(Thread thread)
Join a thread.
Definition util.c:940
void string_to_lowercase(char *s)
Change all char of a string to lowercase.
Definition util.c:355
int string_to_int(const char *s, const int default_value)
Convert a string into an integer.
Definition util.c:457
char * parse_skip_spaces(const char *string)
Skip spaces.
Definition util.c:514
double string_to_real(const char *s, const double default_value)
Convert a string into a real number.
Definition util.c:488
char * parse_word(const char *string, char *word, unsigned int n)
Parse a word.
Definition util.c:562
void relax(int t)
sleep for t ms.
Definition util.c:203
long long string_to_time(const char *string)
Read time as "D:HH:MM:SS.C".
Definition util.c:320
Miscellaneous utilities header.
#define log_close(l)
Close an opened log file.
Definition util.h:435
long long real_clock(void)
#define MIN(a, b)
Definition util.h:101
#define log_print(l,...)
Print into the log file.
Definition util.h:442
#define log_open(l, file)
open a log file if allowed.
Definition util.h:429
#define log_is_open(l)
Check if the log stream can be used.
Definition util.h:448
#define BOUND(var, min, max, name)
Definition util.h:104
static void xboard_setup(Play *play)
Definition xboard.c:154
static void xboard_observer(Result *result)
Search oberver.
Definition xboard.c:38
static void xboard_check_game_over(Play *play)
Check if the game is over.
Definition xboard.c:251
static void xboard_error(const char *format,...)
Print an error.
Definition xboard.c:110
void ui_loop_xboard(UI *ui)
Loop event.
Definition xboard.c:440
static void xboard_analyze(Play *play)
Analyze.
Definition xboard.c:344
Log xboard_log[1]
Definition xboard.c:26
static void xboard_send(const char *format,...)
Send a command to xboard/winboard GUI.
Definition xboard.c:136
static void xboard_move(const int x)
Send a move to xboard/winboard GUI.
Definition xboard.c:166
static int hash_size(int n)
Definition xboard.c:271
static void xboard_book(Play *play)
Send a move from the book, if available.
Definition xboard.c:220
void xboard_stop_analyzing(Play *play)
Stop analyzing.
Definition xboard.c:321
static void xboard_loop_analyze(UI *ui)
Analyze.
Definition xboard.c:367
void ui_init_xboard(UI *ui)
initialize xboard protocol.
Definition xboard.c:72
void ui_free_xboard(UI *ui)
free resources used by xboard protocol.
Definition xboard.c:97
static void xboard_go(UI *ui, XBoardStats *stats)
Definition xboard.c:283
static void xboard_hint(Play *play)
Send a hint.
Definition xboard.c:191