34#define clear_line() bprint(" \r")
43static void bprint(
const char *format, ...)
48 va_start(args, format);
49 vprintf(format, args);
67 r = fread(&link->
score, 1, 1, f);
68 r += fread(&link->
move, 1, 1, f);
81 r = fwrite(&link->
score, 1, 1, f);
82 r += fwrite(&link->
move, 1, 1, f);
101#define foreach_link(l, p) \
102 for ((l) = (p)->link; (l) < (p)->link + (p)->n_link; ++(l))
112 if (depth <= 10)
return 60 - 2 * depth;
113 else if (depth <= 18)
return 39;
114 else if (depth <= 24)
return 36;
115 else if (depth < 30)
return 33;
116 else if (depth < 36)
return 30;
117 else if (depth < 42)
return 66 - depth;
140 warn(
"Board is illegal: Two discs on the same square?\n");
145 warn(
"Board is illegal: Empty center?\n");
153 warn(
"board is not unique\n");
164 warn(
"passing move is wrong\n");
184 warn(
"passing move is wrong\n");
190 warn(
"nomove is wrong\n");
203 for (i = 0; i < position->
n_link; ++i) {
204 for (j = i + 1; j < position->
n_link; ++j) {
206 warn(
"doublon found in links\n");
212 warn(
"doublon found in links/leaf\n");
230 position->
link = NULL;
283 free(position->
link);
297 r = fread(&position->
board->
player, sizeof (
unsigned long long), 1, f);
298 r += fread(&position->
board->
opponent, sizeof (
unsigned long long), 1, f);
300 r += fread(&position->
n_wins, sizeof (
unsigned int), 1, f);
301 r += fread(&position->
n_draws, sizeof (
unsigned int), 1, f);
302 r += fread(&position->
n_losses, sizeof (
unsigned int), 1, f);
303 r += fread(&position->
n_lines, sizeof (
unsigned int), 1, f);
305 r += fread(&position->
score.
value, sizeof (
short), 1, f);
306 r += fread(&position->
score.
lower, sizeof (
short), 1, f);
307 r += fread(&position->
score.
upper, sizeof (
short), 1, f);
309 r += fread(&position->
n_link, 1, 1, f);
310 r += fread(&position->
level, 1, 1, f);
312 if (r != 11)
return false;
321 if (position->
link == NULL)
error(
"cannot allocate opening book position's moves\n");
322 for (i = 0; i < position->
n_link; ++i) {
326 position->
link = NULL;
341 char *line, *s, *old;
352 value = -1; s =
parse_int(old = s + 1, &value);
BOUND(value, -1, 60,
"level");
353 if (s != old && value != -1) {
354 position->
level = value;
371 warn(
"wrong level: %s\n", line);
374 warn(
"missing ',' after board setting\n");
377 warn(
"wrong board: %s\n", line);
381 if (!ok)
warn(
"=> wrong position\n");
398 r = fwrite(&position->
board->
player, sizeof (
unsigned long long), 1, f);
399 r += fwrite(&position->
board->
opponent, sizeof (
unsigned long long), 1, f);
401 r += fwrite(&position->
n_wins, sizeof (
unsigned int), 1, f);
402 r += fwrite(&position->
n_draws, sizeof (
unsigned int), 1, f);
403 r += fwrite(&position->
n_losses, sizeof (
unsigned int), 1, f);
404 r += fwrite(&position->
n_lines, sizeof (
unsigned int), 1, f);
406 r += fwrite(&position->
score.
value, sizeof (
short), 1, f);
407 r += fwrite(&position->
score.
lower, sizeof (
short), 1, f);
408 r += fwrite(&position->
score.
upper, sizeof (
short), 1, f);
410 r += fwrite(&position->
n_link, 1, 1, f);
411 r += fwrite(&position->
level, 1, 1, f);
413 if (r != 11)
return false;
415 for (i = 0; i < position->
n_link; ++i)
434 return (fprintf(f,
"%s,%d,%s,%d\n", b, p->
level, m, p->
leaf.
score) > 0);
447 *board = *position->
board;
449 for (i = 0; i < position->
n_link; ++i) {
470 for (s = 0; s < 8; ++s) {
474 for (i = 0; i < position->
n_link; ++i) {
478 previous = previous->
next = move;
485 previous = previous->
next = move;
488 previous->
next = NULL;
511 const int color = n_empties & 1;
517 fprintf(f,
"\nLevel: %d\n", position->
level);
519 fprintf(f,
"Moves:");
524 fprintf(f,
" <%s:%+02d>", s, move->
score);
526 fprintf(f,
" [%s:%+02d]", s, move->
score);
546 fprintf(f,
"{board:%s; ", b);
547 fprintf(f,
"level:%d; ", position->
level);
549 fprintf(f,
"moves:");
554 fprintf(f,
" <%s:%+02d>", m, move->
score);
556 fprintf(f,
" [%s:%+02d]", m, move->
score);
611 int last = position->
n_link;
623 error(
"cannot allocate opening book position's moves\n");
627 position->
link[last] = *link;
645 if (position->
n_link > 1) {
646 for (i = position->
link; i < position->link + position->
n_link - 1; ++i) {
648 for (j = i + 1; j < position->
link + position->
n_link; ++j) {
795 int tmp_upper, tmp_lower;
802 const int bias = (search_depth & 1) - (n_empties & 1);
818 }
else if (search_depth == n_empties) {
850 tmp_lower = tmp_upper = position->
score.
value;
855 }
else if (search_depth == n_empties) {
889static void position_prune(
Position *position,
Book *book,
const int player_deviation,
const int opponent_deviation,
const int lower,
const int upper)
902 if (position->
score.
value - l->
score <= player_deviation && lower <= l->score && l->
score <= upper) {
905 position_prune(child, book, opponent_deviation, player_deviation, -upper, -lower);
927 for (i = 0; i < position->
n_link; ++i) {
930 if (l[i].score > position->
leaf.
score) position->
leaf = l[i];
931 for (j = i + 1; j < position->
n_link; ++j) l[j - 1] = l[j];
955static void position_deviate(
Position *position,
Book *book,
const int player_deviation,
const int opponent_deviation,
const int lower,
const int upper)
969 if (position->
score.
value - l->
score <= player_deviation && lower <= l->score && l->
score <= upper) {
972 position_deviate(child, book, opponent_deviation, player_deviation, -upper, -lower);
977 if (position->
score.
value - position->
leaf.
score <= player_deviation && lower <= position->leaf.score && position->
leaf.
score <= upper) {
1019 const int bias = (search_depth & 1) - (n_empties & 1);
1025 }
else if (search_depth == n_empties) {
1068 if (move ==
NOMOVE) move = m->
x;
1074 if (is_pv)
hash_feed(search->
pv_table, board, hash_code, depth, selectivity, score, score, move);
1093 bool filled =
false;
1139 *position->
board = *board;
1181 if (a->
n == a->
size) {
1186 error(
"cannot add a position to the book\n");
1215 for (i = 0; i < a->
n; ++i) {
1218 for (j = i + 1; j < a->
n; ++j) {
1254#define foreach_position(p, a, b) \
1255 for (a = b->array; a < b->array + b->n; ++a) \
1256 for (p = a->positions; p < a->positions + a->n; ++p)
1265 time_t t = time(NULL);
1266 struct tm *tm = localtime(&t);
1268 book->
date.
year = tm->tm_year + 1900;
1287 tm.tm_year = book->
date.
year - 1900;
1295 t = difftime(time(NULL), mktime(&tm));
1409 if (book->
array == NULL)
fatal_error(
"cannot allocate space to store the positions");
1425 for (i = 0; i < book->
n; ++i) {
1454 bprint(
"New book %d %d...", level, n_empties);
1473 FILE *f = fopen(file,
"rb");
1476 unsigned int header_edax, header_book;
1477 unsigned char header_version, header_release;
1481 info(
"Loading book from %s...", file);
1482 r = fread(&header_edax,
sizeof (
unsigned int), 1, f);
1483 r += fread(&header_book,
sizeof (
unsigned int), 1, f);
1484 if (r != 2 || header_edax !=
EDAX || header_book !=
BOOK) {
1485 error(
"%s is not an edax opening book", file);
1490 r = fread(&header_version, 1, 1, f);
1491 r += fread(&header_release, 1, 1, f);
1492 if (r != 2 || header_version !=
VERSION) {
1493 error(
"%s is not a compatible version", file);
1498 r = fread(&book->
date,
sizeof book->
date, 1, f);
1502 error(
"Cannot read book settings from %s", file);
1508 while ((book->
n << 4) < book->
n_nodes) book->
n <<= 1;
1511 if (book->
array == NULL) {
1512 error(
"cannot allocate space to store the positions");
1524 error(
"error while reading %s", file);
1549 FILE *f = fopen(file,
"r");
1560 bprint(
"importing book from %s... %d positions", file, book->
n_nodes);
1576 error(
"cannot open \"%s\" to import the opening book\n", file);
1595 f = fopen(file,
"w");
1597 error(
"cannot open file %s", file);
1601 info(
"Exporting book to %s...", file);
1604 error(
"cannot export book to %s", file);
1605 goto book_export_end;
1624 unsigned int header_edax =
EDAX, header_book =
BOOK;
1625 unsigned char header_version =
VERSION, header_release =
RELEASE;
1626 FILE *f = fopen(file,
"wb");
1631 info(
"Saving book to %s...", file);
1634 r = fwrite(&header_edax,
sizeof (
unsigned int), 1, f);
1635 r += fwrite(&header_book,
sizeof (
unsigned int), 1, f);
1636 r += fwrite(&header_version, 1, 1, f);
1637 r += fwrite(&header_release, 1, 1, f);
1638 r += fwrite(&book->
date,
sizeof book->
date, 1, f);
1645 error(
"\nCannot save book to %s", file);
1646 goto book_write_end;
1689 bprint(
"Negamaxing book...");
1707 bprint(
"Linking book...\r");
1715 bprint(
"Linking book...%d done\n", i);
1729 bprint(
"Fixing book...\r");
1736 bprint(
"Fixing book...%d done\n", i);
1752 char file[FILENAME_MAX + 1];
1756 bprint(
"Deepening book...\r");
1763 if (++i % 10 == 0) {
1764 bprint(
"Deepening book...%d\r", i);
1772 bprint(
"Deepening book...%d done\n", i);
1788 char file[FILENAME_MAX + 1];
1795 bprint(
"Correcting solved positions...\r");
1804 bprint(
"\nError found:\n");
1807 bprint(
"instead of <%s:%d>\n\n", s, old_leaf.
score);
1810 bprint(
"Correcting solved positions...%d (%d error found)\r", i, n_error);
1818 bprint(
"Correcting solved positions...%d done (%d error found)\n", i, n_error);
1837 bprint(
"%s...\r", action);
1839 for (a = book->
array; a < book->array + book->
n; ++a)
1840 for (k = 0; k < a->
n; ++k) {
1867 bprint(
"Sorting book...");
1887 char file[FILENAME_MAX + 1];
1899 p->
flag &= ~FLAG_TODO;
1913 bprint(
"Book play... finished\n");
1926 int n_diffs, n_empties, k;
1927 char file[FILENAME_MAX + 1];
1934 for (a = book->
array; a < book->array + book->
n; ++a)
1935 for (k = 0; k < a->
n; ++k) {
1940 if (n_diffs < book->stats.n_nodes + book->
stats.
n_links) {
1952 bprint(
"Book fill... finished\n");
1969 char file[FILENAME_MAX + 1];
1978 bprint(
"Book deviate %d %d:\n", relative_error, absolute_error);
1980 position_deviate(root, book, relative_error, 0, score - absolute_error, score + absolute_error);
1986 bprint(
"Book deviate %d %d:\n", relative_error, absolute_error);
1988 position_deviate(root, book, 0, relative_error, score - absolute_error, score + absolute_error);
1999 bprint(
"Book deviate %d %d...finished\n", relative_error, absolute_error);
2028 for (a = book->
array; a < book->array + book->
n; ++a)
2058 for (a = book->
array; a < book->array + book->
n; ++a)
2080 char file[FILENAME_MAX + 1];
2102 bprint(
"Book enhance %d %d...finished\n", midgame_error, endcut_error);
2115 unsigned long long n_links = 0;
2116 unsigned long long n_leaves = 0;
2117 unsigned long long n_level[61] = {0};
2118 int min_array = book->
n_nodes, max_array = 0;
2124 ++n_level[p->
level];
2130 for (a = book->
array; a < book->array + book->
n; ++a) {
2131 if (a->
n > max_array) max_array = a->
n;
2132 if (a->
n < min_array) min_array = a->
n;
2138 bprint(
"Positions: %d (moves = %lld links + %lld leaves);\n", book->
n_nodes, n_links, n_leaves);
2139 for (i = 0; i < 61; ++i) {
2141 bprint(
"Level %d : %lld nodes\n", i, n_level[i]);
2146 bprint(
"Hash balance: %d < %d < %d\n", min_array, (
int) (book->
n_nodes / book->
n), max_array);
2159 unsigned long long n_games;
2166 bprint(
"\nLines: %lld full games", n_games);
2167 bprint(
" with %.2f%% win, %.2f%% draw, %.2f%% loss",
2170 bprint(
"\n %lld incomplete lines.\n\n", stat.
n_lines - n_games);
2201 unsigned short n_next_player;
2202 unsigned short n_next_opponent;
2212 *n_player = USHRT_MAX;
2215 if (move->
score != bestscore)
continue;
2219 count_bestpath(book, board, &n_next_player, &n_next_opponent,
false);
2220 *n_player =
MIN(*n_player, n_next_opponent);
2221 if ( n_next_player <= USHRT_MAX - *n_opponent ) *n_opponent += n_next_player;
2222 else *n_opponent = USHRT_MAX;
2226 if ( *n_opponent == 0 ) *n_player = *n_opponent = 1;
2231 *n_player = *n_opponent = 1;
2235 bprint(
"\nplayer bestpaths count : %d\n", *n_player);
2236 bprint(
"opponent bestpaths count : %d\n", *n_opponent);
2252void count_board_bestpath(
Book *book,
Board *board,
const int p_lower,
const int o_lower,
const int turn,
unsigned short *n_player,
unsigned short *n_opponent,
bool verbose)
2256 unsigned short n_next_player;
2257 unsigned short n_next_opponent;
2268 *n_player = USHRT_MAX;
2271 if (move->
score < lower)
continue;
2275 count_board_bestpath(book, board, o_lower, p_lower, 1 - turn, &n_next_player, &n_next_opponent,
false);
2276 *n_player =
MIN(*n_player, n_next_opponent);
2277 if ( n_next_player <= USHRT_MAX - *n_opponent ) *n_opponent += n_next_player;
2278 else *n_opponent = USHRT_MAX;
2282 if ( *n_opponent == 0 ) *n_player = *n_opponent = 1;
2285 if ( turn ==
BLACK ) {
2288 position->
flag &= ~FLAG_BESTPATH_BLACK;
2292 *n_player = *n_opponent = 1;
2296 bprint(
"\nplayer bestpaths count : %d\n", *n_player);
2297 bprint(
"opponent bestpaths count : %d\n", *n_opponent);
2311 unsigned short n_player;
2312 unsigned short n_opponent;
2318 memcpy(position, p,
sizeof(
Position));
2340 unsigned short n_player;
2341 unsigned short n_opponent;
2347 memcpy(position, p,
sizeof(
Position));
2386 memcpy(position, p,
sizeof(
Position));
2448 assert(book != NULL);
2449 assert(board !=NULL);
2450 assert(stat != NULL);
2456 if (position->
n_wins == UINT_MAX || position->
n_losses == UINT_MAX || position->
n_draws == UINT_MAX || position->
n_lines == UINT_MAX) {
2498 *position->
board = *board;
2520 char file[FILENAME_MAX + 1];
2536 warn(
"illegal move in game");
2542 while (--n_moves >= 0) {
2559 char file[FILENAME_MAX + 1];
2567 for (i = 0; i < base->
n_games; ++i) {
2570 if (t - t0 > 1000) {
2578 bprint(
"%d games added to book\n", i);
2600 Move stack[99], *iter;
2616 warn(
"illegal move in game");
2621 while (--n_moves >= 0) {
2627 if (iter->
x == stack[n_moves].
x) {
2628 if (iter->
score < bestscore) ++stat->
bad;
2652 for (i = 0; i < base->
n_games; ++i) {
2656 bprint(
"Positions : %llu missing, %llu good, %llu bad (%.2f%% bad)\n", stat.
missing, stat.
good, stat.
bad, (100.0 * stat.
bad)/(stat.
bad + stat.
good));
2683 if (move->
score == bestscore) {
2693 if (base->
n_games % 1000 == 0) {
2742 Move *best, *second_best;
2746 bprint(
"Extracting %d positions at %d ...\n", n_positions, n_empties);
2748 if (i == n_positions)
break;
2754 if (second_best && best->
score > second_best->
score) {
2760 move_print(second_best->
x, n_empties & 1, stdout);
2778 unsigned long long n_hash[256];
2779 unsigned long long n_pos[61], n_leaf[61], n_link[61], n_terminal[61];
2780 unsigned long long n_score[129];
2782 printf(
"\n\nBook statistics:\n");
2784 printf(
"\nHash distribution:\n");
2785 for (i = 0; i < 256; ++i) n_hash[i] = 0;
2786 for (a = book->
array; a < book->array + book->
n; ++a) {
2787 if (a->
n < 256) ++n_hash[a->
n];
2790 printf(
"index positions\n");
2791 for (i = 0; i < 255; ++i)
if (n_hash[i]) printf(
"%5d %12llu\n", i, n_hash[i]);
2792 if (n_hash[i]) printf(
">%4d %12llu\n", i - 1, n_hash[i]);
2794 printf(
"\nStage distribution:\n");
2795 printf(
"stage positions links leaves terminal nodes\n");
2796 for (i = 0; i < 61; ++i) n_pos[i] = n_leaf[i] = n_link[i] = n_terminal[i] = 0;
2801 if (p->
n_link == 0) ++n_terminal[i];
2804 for (i = 0; i < 61; ++i)
if (n_pos[i]) printf(
"%5d %12llu %12llu %12llu %12llu\n", i, n_pos[i], n_link[i], n_leaf[i], n_terminal[i]);
2806 printf(
"\nBest Score Distribution:\n");
2807 printf(
"Score positions\n");
2808 for (i = 0; i < 129; ++i) n_score[i] = 0;
2812 for (i = 0; i < 129; ++i)
if (n_score[i]) printf(
"%+5d %12llu\n", i - 64, n_score[i]);
void base_append(Base *base, const Game *game)
Add a game to a game database.
Definition base.c:696
#define foreach_bit(i, b)
Definition bit.h:39
unsigned long long board_get_hash_code(const Board *board)
Compute a hash code.
Definition board.c:1134
void board_restore(Board *board, const Move *move)
Restore a board.
Definition board.c:487
bool board_is_game_over(const Board *board)
Check if the game is over.
Definition board.c:1203
void board_print(const Board *board, const int player, FILE *f)
Print out the board.
Definition board.c:1230
void board_update(Board *board, const Move *move)
Update a board.
Definition board.c:469
int board_count_empties(const Board *board)
Check if the game is over.
Definition board.c:1216
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
int board_unique(const Board *board, Board *unique)
unique board
Definition board.c:379
void board_init(Board *board)
Set a board to the starting position.
Definition board.c:280
char * board_to_string(const Board *board, const int player, char *s)
convert the to a compact string.
Definition board.c:1272
int get_mobility(const unsigned long long P, const unsigned long long O)
Count legal moves.
Definition board.c:833
void board_check(const Board *board)
Check board consistency.
Definition board.c:291
bool board_equal(const Board *b1, const Board *b2)
Compare two board for equality.
Definition board.c:335
DLL_API unsigned long long get_moves(const unsigned long long P, const unsigned long long O)
Get legal moves.
Definition board.c:621
DLL_API bool can_move(const unsigned long long P, const unsigned long long O)
Check if a player can move.
Definition board.c:797
unsigned long long board_next(const Board *board, const int x, Board *next)
Compute a board resulting of a move played on a previous board.
Definition board.c:517
void board_pass(Board *board)
Passing move.
Definition board.c:503
bool board_is_occupied(const Board *board, const int x)
Check if a square is occupied.
Definition board.c:1180
void board_symetry(const Board *board, const int s, Board *sym)
symetric board
Definition board.c:347
static void position_link(Position *position, Book *book)
Link a position.
Definition book.c:722
static bool position_read(Position *position, FILE *f)
Read a position.
Definition book.c:292
static Position * book_probe(const Book *, const Board *)
Find a position in the book.
Definition book.c:1309
static void bprint(const char *format,...)
print a message on stdout.
Definition book.c:43
static void position_remove_links(Position *position, Book *book)
Remove bad links after book pruning.
Definition book.c:921
bool book_verbose
Definition book.c:36
void book_extract_positions(Book *book, const int n_empties, const int n_positions)
print a set of position.
Definition book.c:2737
static bool position_add_link(Position *position, const Link *link)
Add a link to this position.
Definition book.c:608
static int position_negamax(Position *position, Book *book)
Negamax a position.
Definition book.c:790
void count_bestpath(Book *book, Board *board, unsigned short *n_player, unsigned short *n_opponent, bool verbose)
count the number of best paths in book.
Definition book.c:2196
static void position_array_free(PositionArray *a)
Free resources used by a position array.
Definition book.c:1233
void book_check_base(Book *book, const Base *base)
Check positions from a game database.
Definition book.c:2644
void book_init(Book *book)
Initialize the opening book.
Definition book.c:1396
static void book_expand(Book *book, const char *action, const char *tmp_file)
Expand a book.
Definition book.c:1830
static bool link_read(Link *link, FILE *f)
read a link.
Definition book.c:64
static Position * position_array_probe(PositionArray *a, const Board *board)
Find a position in the array.
Definition book.c:1247
void book_count_bestpath(Book *book, Board *board, Position *position)
count the number of best paths in book.
Definition book.c:2309
static bool position_export(const Position *p, FILE *f)
write a position.
Definition book.c:428
static bool link_is_bad(const Link *link)
check if a link is unvalid.
Definition book.c:92
static void position_sort(Position *position)
Sort the link moves.
Definition book.c:641
static void position_fix(Position *position, Book *book)
Fix a position.
Definition book.c:1126
static void book_clean(Book *book)
Set all positions as undone.
Definition book.c:1353
static bool position_array_add(PositionArray *a, const Position *p)
Add a position to the array.
Definition book.c:1173
void book_deepen(Book *book)
Deepen a book.
Definition book.c:1746
void book_show(Book *book, Board *board)
Display a position from the book.
Definition book.c:2155
#define foreach_position(p, a, b)
Definition book.c:1254
static Position * book_root(Book *book)
Find the initial position in the book.
Definition book.c:1381
void book_count_board_bestpath(Book *book, Board *board, Position *position, const int p_lower, const int o_lower, const int turn)
count the number of "broad" best paths in book.
Definition book.c:2338
static void position_expand(Position *position, Book *book)
Expand a position.
Definition book.c:762
static double book_get_age(Book *book)
Get book age, in seconds.
Definition book.c:1282
void book_add_board(Book *book, const Board *board)
Add a position.
Definition book.c:2485
void book_import(Book *book, const char *file)
Import an opening book.
Definition book.c:1547
void book_play(Book *book)
Play.
Definition book.c:1882
static void position_get_random_move(const Position *position, const Board *board, Move *move, Random *r, const int randomness)
Chose a move at random from the position.
Definition book.c:571
void book_subtree(Book *book, const Board *board)
Prune a book.
Definition book.c:2043
void book_enhance(Book *book, Board *board, const int midgame_error, const int endcut_error)
Enhance a book.
Definition book.c:2075
void count_board_bestpath(Book *book, Board *board, const int p_lower, const int o_lower, const int turn, unsigned short *n_player, unsigned short *n_opponent, bool verbose)
count the number of "broad" best paths in book.
Definition book.c:2252
struct PositionArray PositionArray
An array with positions.
void book_info(Book *book)
display some book's informations.
Definition book.c:2111
void book_get_line(Book *book, const Board *board, const Move *move, Line *line)
Get a variation from the book.
Definition book.c:2401
void book_correct_solved(Book *book)
Correct wrong solved score in the book.
Definition book.c:1782
#define foreach_link(l, p)
Definition book.c:101
static void extract_skeleton(Book *book, Board *board, Line *pv, Base *base)
Extract book lines to a game base.
Definition book.c:2671
static int position_get_moves(const Position *position, const Board *board, MoveList *movelist)
Get moves from a position.
Definition book.c:463
void book_negamax(Book *book)
Negamax a book.
Definition book.c:1684
bool book_get_random_move(Book *book, const Board *board, Move *move, const int randomness)
Get a move at random from the opening book.
Definition book.c:2426
static bool position_is_ok(const Position *position)
Check if position is ok or need fixing.
Definition book.c:130
static void book_add(Book *, const Position *)
Add a position to the book.
Definition book.c:1322
static void book_remove(Book *book, const Position *p)
Remove a position from the book.
Definition book.c:1338
int book_get_moves_with_position(Book *book, const Board *board, MoveList *movelist, Position *position)
Get a list of moves from the book.
Definition book.c:2380
static void position_merge(Position *dest, const Position *src)
Merge a position with another one.
Definition book.c:257
static void position_prune(Position *position, Book *book, const int player_deviation, const int opponent_deviation, const int lower, const int upper)
Prune a position.
Definition book.c:889
static void position_print(const Position *, const Board *, FILE *)
print a position in a compact but readable format.
Definition book.c:538
void book_export(Book *book, const char *file)
Export an opening book.
Definition book.c:1589
void book_free(Book *book)
Free resources used by the opening book.
Definition book.c:1422
void book_preprocess(Book *book)
clean opening book.
Definition book.c:1436
void book_check_game(Book *book, MoveHash *hash, const Game *game, BookCheckGame *stat)
Check positions from a game.
Definition book.c:2597
void book_save(Book *book, const char *file)
Save an opening book.
Definition book.c:1622
void book_fill(Book *book, const int depth)
Fill a book.
Definition book.c:1922
static void position_show(const Position *position, const Board *board, FILE *f)
print a position in a readable format.
Definition book.c:506
static bool position_write(const Position *position, FILE *f)
Write a position.
Definition book.c:393
static void board_feed_hash(Board *board, const Book *book, Search *search, const bool is_pv)
Feed hash from a position.
Definition book.c:1051
void book_stats_clean(Book *book)
Definition book.c:1365
static bool link_write(const Link *link, FILE *f)
write a link.
Definition book.c:78
bool book_get_moves(Book *book, const Board *board, MoveList *movelist)
Get a list of moves from the book.
Definition book.c:2360
static int get_book_depth(const int depth)
return the number of plies from where the search is solving.
Definition book.c:110
void book_fix(Book *book)
Fix a book.
Definition book.c:1723
void book_sort(Book *book)
Sort a book.
Definition book.c:1862
void book_merge(Book *dest, const Book *src)
Merge two opening books.
Definition book.c:1665
static void position_array_init(PositionArray *a)
Initialize the array.
Definition book.c:1160
static bool position_import(Position *position, FILE *f)
Read a position.
Definition book.c:339
void book_link(Book *book)
Link a book.
Definition book.c:1701
static void position_unique(Position *position)
Make position unique, regarding symetries.
Definition book.c:442
#define BOOK_DEBUG
Definition book.c:31
void book_get_game_stats(Book *book, const Board *board, GameStats *stat)
Get game statistics from a position.
Definition book.c:2444
Position * book_show_for_api(Book *book, Board *board)
Display a position from the book.
Definition book.c:2181
void book_feed_hash(const Book *book, Board *board, Search *search)
feed hash table from the opening book.
Definition book.c:2824
const Link BAD_LINK
Definition book.c:56
static bool position_array_remove(PositionArray *a, const Position *p)
Remove a position from an array.
Definition book.c:1211
void book_prune(Book *book)
Prune a book.
Definition book.c:2010
static bool board_fill(Board *board, Book *book, int depth)
Fill the opening book.
Definition book.c:1088
struct BookCheckGame BookCheckGame
void book_stats(Book *book)
print book statistics.
Definition book.c:2773
void book_extract_skeleton(Book *book, Base *base)
Extract book draws to a game base.
Definition book.c:2709
static void position_search(Position *position, Book *book)
Evaluate a position.
Definition book.c:668
void book_deviate(Book *book, Board *board, const int relative_error, const int absolute_error)
Deviate a book.
Definition book.c:1963
void book_new(Book *book, int level, int n_empties)
Create a new opening book.
Definition book.c:1450
void book_load(Book *book, const char *file)
Load the opening book.
Definition book.c:1471
static const int BOOK_INFO_RESOLUTION
Definition book.c:32
static void position_enhance(Position *position, Book *book)
Enhance a position.
Definition book.c:997
static void position_deviate(Position *position, Book *book, const int player_deviation, const int opponent_deviation, const int lower, const int upper)
Deviate a position.
Definition book.c:955
void book_add_game(Book *book, const Game *game)
Add positions from a game.
Definition book.c:2515
void book_add_base(Book *book, const Base *base)
Add positions from a game database.
Definition book.c:2556
void book_stop_count_bestpath(Book *book)
Definition book.c:2323
static void position_init(Position *position)
Initialize a position.
Definition book.c:225
static void book_set_date(Book *book)
Set book date.
Definition book.c:1263
static void position_free(Position *position)
Free resources used by a position.
Definition book.c:281
#define FLAG_TODO
Definition book.h:99
#define FLAG_DONE
Definition book.h:98
#define FLAG_BESTPATH_BLACK
Definition book.h:100
#define TIME_MAX
Definition const.h:61
#define SCORE_INF
Definition const.h:52
#define VERSION
Definition const.h:86
#define HOUR
Definition const.h:64
#define EDAX
Definition const.h:91
#define RELEASE
Definition const.h:87
@ PASS
Definition const.h:37
@ NOMOVE
Definition const.h:37
@ E6
Definition const.h:34
@ C4
Definition const.h:32
@ F5
Definition const.h:33
@ F4
Definition const.h:32
@ F6
Definition const.h:34
@ D6
Definition const.h:34
@ H8
Definition const.h:36
@ WHITE
Definition const.h:43
@ BLACK
Definition const.h:42
#define BOOK
Definition const.h:90
#define BESTPATH_BEST
Definition const.h:119
@ RUNNING
Definition const.h:71
@ STOP_PONDERING
Definition const.h:73
void line_to_game(const Board *initial_board, const Line *line, Game *game)
Build a game from an initial position and a move sequence.
Definition game.c:415
void hash_feed(HashTable *hash_table, const unsigned long long hash_code, const int depth, const int selectivity, const int lower, const int upper, const int move)
Feed hash table (from Cassio).
Definition hash-lock-free.c:496
Move * movelist_best(MoveList *movelist)
Return the best move of the list.
Definition move.c:411
void line_push(Line *line, const int x)
Add a move to the sequence.
Definition move.c:561
void movehash_delete(MoveHash *hash)
Free the hash table.
Definition move.c:730
void movehash_init(MoveHash *hash, int bitsize)
Initialisation of the hash table.
Definition move.c:715
void move_print(const int x, const int player, FILE *f)
Print out a move.
Definition move.c:110
const Move MOVE_PASS
Definition move.c:26
void movelist_sort(MoveList *movelist)
Sort all moves.
Definition move.c:505
Move * movelist_first(MoveList *movelist)
Return the first move of the list.
Definition move.c:422
bool movehash_append(MoveHash *hash, const Board *b, const int x)
Append a position to the hash table.
Definition move.c:745
Move * move_next(Move *move)
Return the next move from the list.
Definition move.c:400
void line_init(Line *line, const int player)
Initialize a sequence of moves.
Definition move.c:549
void line_pop(Line *line)
Remove the last move from a sequence.
Definition move.c:578
int movelist_get_moves(MoveList *movelist, const Board *board)
Get moves from a position.
Definition move.c:298
Move * movelist_exclude(MoveList *movelist, const int move)
Exclude a move.
Definition move.c:516
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
int symetry(int x, const int sym)
Get a symetric square coordinate.
Definition move.c:47
#define foreach_move(iter, movelist)
Definition move.h:78
#define foreach_best_move(iter, movelist)
Definition move.h:82
Options options
Definition options.c:22
void * search_run(void *v)
Search the bestmove of a given board.
Definition root.c:810
void search_set_level(Search *search, const int level, const int n_empties)
Set the search level.
Definition search.c:609
const int NO_SELECTIVITY
Definition search.c:94
struct Level LEVEL[61][61]
Definition search.c:144
void search_cleanup(Search *search)
Clean-up some search data.
Definition search.c:578
void search_set_board(Search *search, const Board *board, const int player)
Set the board to analyze.
Definition search.c:593
Game * game
Definition base.h:49
int n_games
Definition base.h:50
unsigned long long player
Definition board.h:27
unsigned long long opponent
Definition board.h:27
unsigned long long bad
Definition book.c:2586
unsigned long long missing
Definition book.c:2584
unsigned long long good
Definition book.c:2585
The opening book.
Definition book.h:25
int endcut_error
Definition book.h:35
short year
Definition book.h:27
int n
Definition book.h:45
struct PositionArray * array
Definition book.h:43
int n_empties
Definition book.h:33
bool need_saving
Definition book.h:47
int n_links
Definition book.h:40
int level
Definition book.h:32
Random random[1]
Definition book.h:48
char minute
Definition book.h:29
char second
Definition book.h:29
char day
Definition book.h:28
int n_todo
Definition book.h:41
char hour
Definition book.h:29
int n_nodes
Definition book.h:39
char month
Definition book.h:28
volatile Stop count_bestpath_stop
Definition book.h:50
int midgame_error
Definition book.h:34
Search * search
Definition book.h:49
Game statistics.
Definition book.h:57
unsigned long long n_draws
Definition book.h:59
unsigned long long n_losses
Definition book.h:60
unsigned long long n_lines
Definition book.h:61
unsigned long long n_wins
Definition book.h:58
char move[60]
Definition game.h:33
Board initial_board[1]
Definition game.h:23
int depth
Definition search.h:89
int selectivity
Definition search.h:90
int n_moves
Definition move.h:37
a move (with its score) linking to another Position.
Definition book.h:68
unsigned char move
Definition book.h:70
signed char score
Definition book.h:69
int n_moves
Definition move.h:31
Move move[MAX_MOVE+2]
Definition move.h:30
int score
Definition move.h:23
struct Move * next
Definition move.h:25
unsigned long long flipped
Definition move.h:21
int x
Definition move.h:22
int level
Definition options.h:40
char * book_file
Definition options.h:59
int hash_table_size
Definition options.h:25
An array with positions.
Definition book.c:1148
int size
Definition book.c:1151
Position * positions
Definition book.c:1149
int n
Definition book.c:1150
A position stored in the book.
Definition book.h:77
unsigned int n_wins
Definition book.h:87
Link leaf
Definition book.h:79
struct Position::@3 score
unsigned int n_draws
Definition book.h:88
unsigned char n_link
Definition book.h:94
unsigned short n_opponent_bestpaths
Definition book.h:85
unsigned char level
Definition book.h:95
unsigned int n_lines
Definition book.h:90
unsigned int n_losses
Definition book.h:89
unsigned short n_player_bestpaths
Definition book.h:84
Board board[1]
Definition book.h:78
short value
Definition book.h:92
short upper
Definition book.h:92
Link * link
Definition book.h:86
short lower
Definition book.h:92
unsigned char flag
Definition book.h:83
int move
Definition search.h:44
int score
Definition search.h:45
const char * separator
Definition search.h:145
int n_empties
Definition search.h:99
MoveList movelist[1]
Definition search.h:132
Result * result
Definition search.h:151
const char * header
Definition search.h:144
bool time_per_move
Definition search.h:141
int player
Definition search.h:100
struct Search::@25 options
int verbosity
Definition search.h:142
HashTable pv_table[1]
Definition search.h:104
HashTable hash_table[1]
Definition search.h:103
Board board[1]
Definition search.h:96
char * parse_move(const char *string, const Board *board, Move *move)
Parse a move.
Definition util.c:627
char * file_add_ext(const char *base, const char *ext, char *file)
Add an extension to a string.
Definition util.c:907
char * parse_int(const char *string, int *result)
Parse an integer.
Definition util.c:761
char * string_read_line(FILE *f)
Read a line.
Definition util.c:265
unsigned long long random_get(Random *random)
Pseudo-random number generator.
Definition util.c:1043
void random_seed(Random *random, const unsigned long long seed)
Pseudo-random number seed.
Definition util.c:1062
char * parse_find(const char *string, const int c)
Find a char.
Definition util.c:545
char * parse_board(const char *string, Board *board, int *player)
Parse a board.
Definition util.c:682
Miscellaneous utilities header.
#define error(...)
Display an error message as "ERROR : filename : funcname : line number : ...".
Definition util.h:361
long long real_clock(void)
#define MIN(a, b)
Definition util.h:101
#define fatal_error(...)
Display an error message as "FATAL_ERROR : file name : function name : line number : ....
Definition util.h:349
#define info(...)
Display a message.
Definition util.h:382
#define warn(...)
Display a warning message as "WARNING : ... ".
Definition util.h:373
#define BOUND(var, min, max, name)
Definition util.h:104