My Project
base.c
Go to the documentation of this file.
1
11#include "base.h"
12#include "options.h"
13#include "search.h"
14#include "perft.h"
15
16#include <assert.h>
17#include <stdio.h>
18#include <time.h>
19
28static void wthor_header_set(WthorHeader *wheader, unsigned int n_games, unsigned int n, unsigned int year)
29{
30 time_t t;
31 struct tm *date;
32
33 t = time(NULL); date = localtime(&t);
34 wheader->century = date->tm_year / 100 + 19;
35 wheader->year = date->tm_year % 100;
36 wheader->month = date->tm_mon + 1;
37 wheader->day = date->tm_mday;
38 wheader->n_games = n_games;
39 wheader->n = n;
40 if (year) wheader->game_year = year;
41 else wheader->game_year = date->tm_year + 1900;
42 wheader->board_size = 8;
43 wheader->game_type = 0;
44 wheader->depth = 1;
45 wheader->reserved = 0;
46}
47
54static bool wthor_header_read(WthorHeader *wheader, FILE *f)
55{
56 int r;
57
58 r = fread(&wheader->century, 1, 1, f);
59 r += fread(&wheader->year, 1, 1, f);
60 r += fread(&wheader->month, 1, 1, f);
61 r += fread(&wheader->day, 1, 1, f);
62 r += fread(&wheader->n_games, 4, 1, f); // ok only on intel-x86 endianness.
63 r += fread(&wheader->n, 2, 1, f);
64 r += fread(&wheader->game_year, 2, 1, f);
65 r += fread(&wheader->board_size, 1, 1, f);
66 r += fread(&wheader->game_type, 1, 1, f);
67 r += fread(&wheader->depth, 1, 1, f);
68 r += fread(&wheader->reserved, 1, 1, f);
69
70 if (r != 11) {
71 warn("Cannot read wthor header (r = %d)\n", r);
72 return false;
73 }
74
75 return true;
76}
77
84static bool wthor_header_write(WthorHeader *wheader, FILE *f)
85{
86 int r;
87
88 r = fwrite(&wheader->century, 1, 1, f);
89 r += fwrite(&wheader->year, 1, 1, f);
90 r += fwrite(&wheader->month, 1, 1, f);
91 r += fwrite(&wheader->day, 1, 1, f);
92 r += fwrite(&wheader->n_games, 4, 1, f); // ok only on intel-x86 endianness.
93 r += fwrite(&wheader->n, 2, 1, f);
94 r += fwrite(&wheader->game_year, 2, 1, f);
95 r += fwrite(&wheader->board_size, 1, 1, f);
96 r += fwrite(&wheader->game_type, 1, 1, f);
97 r += fwrite(&wheader->depth, 1, 1, f);
98 r += fwrite(&wheader->reserved, 1, 1, f);
99
100 if (r != 11) {
101 warn("Cannot write wthor header (r = %d)\n", r);
102 return false;
103 }
104
105 return true;
106}
107
114{
115 base->n_players = 1;
116 base->player = (char (*)[20]) malloc(sizeof (*base->player));
117 if (base->player) {
118 strncpy(base->player[0], "?", 20); // used on purpose, as strncpy fills with '\0' the field name
119 } else {
120 warn("Cannot allocate Wthor players' array\n");
121 base->n_players = 0;
122 }
123}
124
131static void wthor_players_load(WthorBase *base, const char *file)
132{
133 FILE *f;
134 WthorHeader header[1];
135 int i, r;
136
137 r = base->n_players = 0;
138
139 if ((f = fopen(file, "rb")) == NULL) {
140 warn("Cannot open Wthor players' file %s\n", file);
141 fprintf(stderr, "Creating a new %s file\n\n", file);
142 wthor_players_init(base);
143 return;
144 }
145
146 if (wthor_header_read(header, f)) {;
147
148 base->n_players = header->n;
149
150 base->player = (char (*)[20]) malloc(base->n_players * sizeof (*base->player));
151 if (base->player) {
152 for (i = 0; i < base->n_players; ++i) {
153 r += fread(base->player[i], 20, 1, f);
154 }
155 } else {
156 warn("Cannot allocate Wthor players' array\n");
157 }
158
159 if (r != base->n_players) {
160 warn("Error while reading Wthor players' file %s %d/%d\n", file, r, base->n_players);
161 base->n_players = 0;
162 }
163 }
164
165 fclose(f);
166}
167
174static void wthor_players_save(WthorBase *base, const char *file)
175{
176 FILE *f;
177 WthorHeader header[1];
178 int i, r;
179
180 r = 0;
181
182 wthor_header_set(header, 0, base->n_players, 0);
183
184 if ((f = fopen(file, "wb")) == NULL) {
185 warn("Cannot open Wthor players' file %s\n", file);
186 return;
187 }
188
189 if (wthor_header_write(header, f)) {
190
191 for (i = 0; i < base->n_players; ++i) {
192 r += fwrite(base->player[i], 20, 1, f);
193 }
194
195 if (r != base->n_players) {
196 warn("Error while reading Wthor players' file %s %d/%d\n", file, r, base->n_players);
197 base->n_players = 0;
198 }
199 }
200
201 fclose(f);
202}
203
210int wthor_player_get(WthorBase *base, const char *name)
211{
212 int i, n;
213 char (*player)[20];
214
215 assert(base != NULL && name != NULL);
216 assert(base->player != NULL && base->n_players > 0);
217
218 for (i = 0; i < base->n_players; ++i) {
219 if (strcmp(name, base->player[i]) == 0) return i;
220 }
221
222 n = base->n_players + 1;
223 player = (char (*)[20]) realloc(base->player, n * sizeof (*base->player));
224 if (player) {
225 base->player = player;
226 base->n_players = n;
227 strncpy(base->player[i], name, 20); // used on purpose, as strncpy fills with '\0' the field name
228 base->player[i][19] = '\0'; // force null terminated string
229 } else {
230 warn("Cannot allocate Wthor players' array\n");
231 i = 0;
232 }
233
234 return i;
235}
236
243static void wthor_tournaments_load(WthorBase *base, const char *file)
244{
245 FILE *f;
246 WthorHeader header[1];
247 int i, r;
248
249 r = 0;
250 base->n_tournaments = 0;
251
252 if ((f = fopen(file, "rb")) == NULL) {
253 warn("Cannot open Wthor tournaments' file %s\n", file);
254 return;
255 }
256
257 if (wthor_header_read(header, f)) {
258 base->n_tournaments = header->n;
259
260 base->tournament = (char (*)[26]) malloc(base->n_tournaments * sizeof (*base->tournament));
261 if (base->tournament) {
262 for (i = r = 0; i < base->n_tournaments; ++i) {
263 r += fread(base->tournament[i], 26, 1, f);
264 }
265 } else {
266 warn("Cannot allocate Wthor tournaments' array\n");
267 }
268
269 if (r != base->n_tournaments) {
270 warn("Error while reading %s %d/%d\n", file, r, base->n_tournaments);
271 base->n_tournaments = 0;
272 }
273 }
274
275 fclose(f);
276}
277
278#if 0 // Unused
285static void wthor_tournaments_save(WthorBase *base, const char *file)
286{
287 FILE *f;
288 WthorHeader header[1];
289 int i, r;
290
291 r = 0;
292
293 if ((f = fopen(file, "rw")) == NULL) {
294 warn("Cannot open Wthor tournaments' file %s\n", file);
295 return;
296 }
297 wthor_header_set(header, 0, base->n_tournaments, 0);
298 if (wthor_header_write(header, f)) {
299 for (i = r = 0; i < base->n_tournaments; ++i) {
300 r += fwrite(base->tournament[i], 26, 1, f);
301 }
302 if (r != base->n_tournaments) {
303 warn("Error while writing %s %d/%d\n", file, r, base->n_tournaments);
304 }
305 }
306
307 fclose(f);
308}
309#endif
310
317{
318 base->n_tournaments = 0;
319 base->n_players = 0;
320 base->n_games = 0;
321 base->tournament = NULL;
322 base->player = NULL;
323 base->game = NULL;
324}
325
332bool wthor_load(WthorBase *base, const char *file)
333{
334 FILE *f;
335 char path[FILENAME_MAX];
336 int r = 0;
337
338 wthor_init(base);
339
340 path_get_dir(file, path); strcat(path, "WTHOR.TRN");
341 wthor_tournaments_load(base, path);
342
343 path_get_dir(file, path); strcat(path, "WTHOR.JOU");
344 wthor_players_load(base, path);
345
346 if ((f = fopen(file, "rb")) != NULL) {
347 if (wthor_header_read(base->header, f) && base->header->board_size == 8) {
348 base->n_games = base->header->n_games;
349
350 base->game = (WthorGame*) malloc(base->n_games * sizeof (WthorGame));
351 if (base->game) {
352 r = (fread(base->game, sizeof (WthorGame), base->n_games, f) == (unsigned) base->n_games);
353 if (!r) warn("Error while reading %s\n", file);
354 } else {
355 warn("Cannot allocate whor games\n");
356 }
357 }
358 fclose(f);
359 } else {
360 base->n_games = 0;
361 base->game = NULL;
362 warn("Cannot open file %s\n", file);
363 }
364
365 return r != 0;
366}
367
374{
375 free(base->player);
376 free(base->tournament);
377 free(base->game);
378 wthor_init(base);
379}
380
387bool wthor_save(WthorBase *base, const char *file)
388{
389 FILE *f;
390 char path[FILENAME_MAX];
391 int r = 0;
392
393 path_get_dir(file, path); strcat(path, "WTHOR.JOU");
394 wthor_players_save(base, path);
395
396 if ((f = fopen(file, "wb")) != NULL) {
397 wthor_header_set(base->header, base->n_games, 0, 0);
398 r = wthor_header_write(base->header, f);
399 if (base->game) {
400 r += (fwrite(base->game, sizeof (WthorGame), base->n_games, f) == (unsigned) base->n_games);
401 }
402 if (r != base->n_games) warn("Error while writing %s\n", file);
403 fclose(f);
404 } else {
405 warn("Cannot open file %s\n", file);
406 }
407
408 return r;
409}
410
417bool base_to_wthor(const Base *base, WthorBase *wthor)
418{
419 bool ok = true;
420 int i, j;
421
422 j = wthor->n_games;
423 wthor->n_games = j + base->n_games;
424 wthor->game = (WthorGame*) realloc(wthor->game, wthor->n_games * sizeof (WthorGame));
425 if (wthor->game) {
426 for (i = 0; i < base->n_games; ++i, ++j) {
427 game_to_wthor(base->game + i, wthor->game + j);
428 wthor->game[j].black = wthor_player_get(wthor, base->game[i].name[BLACK]);
429 wthor->game[j].white = wthor_player_get(wthor, base->game[i].name[WHITE]);
430 }
431 } else {
432 warn("Cannot allocate wthor games\n");
433 ok = false;
434 }
435
436 return ok;
437}
438
446void wthor_print_game(WthorBase *base, int i, FILE *f)
447{
448 Game game[1];
449
450 if (0 <= i && i < base->n_games) {
451
452 fprintf(f, "Game #%d: %s: %4d - %s vs. %s: ",
453 i, base->tournament[base->game[i].tournament],
454 base->header->game_year,
455 base->player[base->game[i].black],
456 base->player[base->game[i].white]);
457
458 wthor_to_game(base->game + i, game);
459 game_export_text(game, f);
460
461 fprintf(f, "Theoric score %d empties : %+02d, ", base->header->depth, base->game[i].theoric_score);
462 fprintf(f, "Score final : %+02d (as black disc count.)\n", base->game[i].score);
463 }
464}
465
474static void wthorgame_get_board(WthorGame *game, const int n_empties, Board *board, int *player)
475{
476 int i;
477 Move move[1];
478 char s_move[4];
479
480 *player = BLACK; board_init(board);
481 for (i = 0; i < 60 - n_empties && game->x[i]; ++i) {
482 if (board_is_pass(board)) {
483 board_pass(board); *player ^= 1;
484 }
485 board_get_move(board, move_from_wthor(game->x[i]), move);
486 if (board_check_move(board, move)) {
487 board_update(board, move); *player ^= 1;
488 } else {
489 warn("Illegal move %s\n", move_to_string(move->x, *player, s_move));
490 break;
491 }
492 }
493}
494
502int pv_check(const Board *init_board, Line *pv, Search *search)
503{
504 Game game[1];
505
506 line_to_game(init_board, pv, game);
507 return game_analyze(game, search, board_count_empties(init_board), false);
508}
509
516void wthor_test(const char *file, Search *search)
517{
518 WthorBase base[1];
519 WthorGame *wthor;
520 Board board[1];
521 int player;
522 int score;
523 int n_empties;
524 int n_failure;
525 long long n_nodes;
526 long long t;
527 int n_err;
528
529 if (wthor_load(base, file)) {
530
531 if (search->options.verbosity == 1) {
532 if (search->options.header) puts(search->options.header);
533 if (search->options.separator) puts(search->options.separator);
534 }
535
536 n_failure = 0;
537 n_nodes = 0;
538 t = 0;
539
540 foreach_wthorgame(wthor, base) {
541 wthorgame_get_board(wthor, base->header->depth, board, &player);
542 n_empties = board_count_empties(board);
543 if (n_empties != base->header->depth && !board_is_game_over(board)) {
544 warn("Incomplete or Illegal game: %d empties\n", n_empties);
545 wthor_print_game(base, wthor - base->game, stderr);
546 continue;
547 }
548
549 if (player == WHITE) score = 64 - 2 * wthor->theoric_score;
550 else score = 2 * wthor->theoric_score - 64;
551 if (abs(score) > 64) {
552 warn("Impossible theoric score:\n");
553 wthor_print_game(base, wthor - base->game, stderr);
554 continue;
555 }
556
557 search_cleanup(search);
558 search_set_board(search, board, player);
559 search_set_level(search, 60, base->header->depth);
560 search_run(search);
561 if (search->options.verbosity) putchar('\n');
562 n_nodes += search->result->n_nodes;
563 t += search->result->time;
564 if (score != search->result->score) {
565 warn("Wrong theoric score: %+d (Wthor) instead of %+d (Edax)\n", score, search->result->score);
566 wthor_print_game(base, wthor - base->game, stderr);
567 ++n_failure;
568 assert(false); // stop here when debug is on
569 }
570
571 if (options.pv_check) {
572 Line pv;
573 line_copy(&pv, search->result->pv, 0);
574 n_err = pv_check(board, &pv, search);
575 if (n_err) {
576 char s[80];
577 warn("Wrong pv:\n");
578 board_print(board, player, stderr);
579 fprintf(stderr, "setboard %s\nplay ", board_to_string(board, player, s));
580 line_print(&pv, 200, " ", stderr);
581 putc('\n', stderr); putc('\n', stderr);
582 assert(false); // stop here when debug is on
583 }
584 }
585
586 if (search->options.verbosity == 0) {
587 printf("%s game: %4d, error: %2d ; ", file, (int)(wthor - base->game) + 1, n_failure);
588 printf("%lld n, ", n_nodes); time_print(t, false, stdout); putchar('\r');
589 fflush(stdout);
590 }
591 }
592 if (search->options.verbosity == 1) {
593 if (search->options.separator) puts(search->options.separator);
594 }
595 putchar('\n');
596
597 wthor_free(base);
598 }
599 return;
600}
601
611void wthor_eval(const char *file, Search *search, unsigned long long histogram[129][65])
612{
613 WthorBase base[1];
614 WthorGame *wthor;
615 Board board[1];
616 int player;
617 int score;
618 int n_empties;
619
620 if (wthor_load(base, file)) {
621 foreach_wthorgame(wthor, base) {
622 wthorgame_get_board(wthor, base->header->depth, board, &player);
623 n_empties = board_count_empties(board);
624 if (n_empties != base->header->depth && !board_is_game_over(board)) {
625 continue;
626 }
627
628 if (player == WHITE) score = 64 - 2 * wthor->theoric_score;
629 else score = 2 * wthor->theoric_score - 64;
630 if (abs(score) > 64) {
631 continue;
632 }
633
634 search_cleanup(search);
635 search_set_board(search, board, player);
636 search_set_level(search, options.level, base->header->depth);
637 search_run(search);
638 ++histogram[search->result->score + 64][(score + 64) / 2];
639 }
640 wthor_free(base);
641 }
642 return;
643}
644
651void wthor_edaxify(const char *file)
652{
653 WthorBase base[1];
654 WthorGame *wthor;
655
656 if (wthor_load(base, file)) {
657 foreach_wthorgame(wthor, base) {
658 wthor->black = 1368; // "Edax (delorme)"
659 wthor->white = 1368; // "Edax (delorme)"
660 wthor->tournament = 157; // "Etudes"
661 }
662 wthor_save(base, file);
663 wthor_free(base);
664 }
665}
666
672void base_init(Base *base)
673{
674 base->size = 0;
675 base->n_games = 0;
676 base->game = NULL;
677}
678
684void base_free(Base *base)
685{
686 free(base->game);
687 base_init(base);
688}
689
696void base_append(Base *base, const Game *game)
697{
698 if (base->n_games == base->size) {
699 Game *ptr;
700 int size = base->size;
701
702 if (size == 0) size = 16384;
703 else size *= 2;
704 ptr = (Game*) realloc(base->game, size * sizeof (Game));
705 if (ptr == NULL) {
706 error("cannot reallocate base game");
707 return;
708 }
709 base->game = ptr;
710 base->size = size;
711 }
712 base->game[base->n_games++] = *game;
713}
714
720void base_unique(Base *base)
721{
722 int i, j, k;
723 bool found;
724
725 for (i = k = 0; i < base->n_games; ++i) {
726 for (j = 0, found = false; j < k && !found; ++j)
727 found = game_equals(base->game + j, base->game + i);
728 if (!found) base->game[k++] = base->game[i];
729 }
730
731 base->n_games = k;
732}
733
740bool base_load(Base *base, const char *file)
741{
742 void (*load)(Game*, FILE*) = game_import_text;
743 Game game[1];
744 FILE *f;
745 char ext[8];
746 int l;
747 WthorHeader header[1];
748
749 l = strlen(file); strcpy(ext, file + l - 4); string_to_lowercase(ext);
750 if (strcmp(ext, ".txt") == 0) load = game_import_text;
751 else if (strcmp(ext, ".ggf") == 0) load = game_import_ggf;
752 else if (strcmp(ext, ".sgf") == 0) load = game_import_sgf;
753 else if (strcmp(ext, ".pgn") == 0) load = game_import_pgn;
754 else if (strcmp(ext, ".wtb") == 0) load = game_import_wthor;
755 else if (strcmp(ext, ".edx") == 0) load = game_read;
756 else {
757 warn("Unknown game format extension: %s\n", ext);
758 return false;
759 }
760
761 if (load == game_import_wthor) f = fopen(file, "rb");
762 else f = fopen(file, "r");
763 if (f == NULL) {
764 warn("Cannot open file %s\n", file);
765 return false;
766 }
767
768 info("loading games...");
769 if (load == game_import_wthor) wthor_header_read(header, f);
770 for (;;) {
771 load(game, f);
772 if (ferror(f) || feof(f)) break;
773 base_append(base, game);
774 }
775 info("done (%d games loaded)\n", base->n_games);
776
777 fclose(f);
778
779 return base->n_games > 0;
780}
781
788void base_save(const Base *base, const char *file)
789{
790 void (*save)(const Game*, FILE*)= game_export_text;
791 FILE *f;
792 char ext[8];
793 int i, l;
794 WthorBase wbase;
795 Base old;
796
797 l = strlen(file); strcpy(ext, file + l - 4); string_to_lowercase(ext);
798 if (strcmp(ext, ".txt") == 0) save = game_export_text;
799 else if (strcmp(ext, ".ggf") == 0) save = game_export_ggf;
800 else if (strcmp(ext, ".sgf") == 0) save = game_export_sgf;
801 else if (strcmp(ext, ".pgn") == 0) save = game_export_pgn;
802 else if (strcmp(ext, ".wtb") == 0) {
803 wthor_load(&wbase, file);
804 base_to_wthor(base, &wbase);
805 wthor_save(&wbase, file);
806 wthor_free(&wbase);
807 return;
808 } else if (strcmp(ext, ".edx") == 0) save = game_write;
809 else {
810 warn("Unknown game format extension: %s\n", ext);
811 return;
812 }
813
814 base_init(&old);
815 base_load(&old, file);
816 for (i = 0; i < base->n_games; ++i) {
817 base_append(&old, base->game + i);
818 }
819
820 f = fopen(file, "w");
821 if (f == NULL) {
822 warn("Cannot open file %s\n", file);
823 return;
824 }
825 for (i = 0; i < old.n_games && !ferror(f); ++i) {
826 save(old.game + i, f);
827 }
828
829 fclose(f);
830
831}
832
833
841void base_to_problem(Base *base, const int n_empties, const char *problem)
842{
843 int i;
844 Board board[1];
845 char s[80];
846 FILE *f;
847
848 f = fopen(problem, "w");
849
850 for (i = 0; i < base->n_games; ++i) {
851 if (game_get_board(base->game + i, 60 - n_empties, board)) {
852 board_to_string(board, n_empties & 1, s);
853 fprintf(f, "%s\n", s);
854 }
855 }
856
857 fclose(f);
858}
859
867void base_to_FEN(Base *base, const int n_empties, const char *problem)
868{
869 int i;
870 Board board[1];
871 FILE *f;
872
873 f = fopen(problem, "w");
874
875 for (i = 0; i < base->n_games; ++i) {
876 if (game_get_board(base->game + i, 60 - n_empties, board)) {
877 board_print_FEN(board, n_empties & 1, f);
878 putc('\n', f);
879 }
880 }
881
882 fclose(f);
883}
884
893void base_analyze(Base *base, Search *search, const int n_empties, const bool apply_correction)
894{
895 int i;
896 int n_error;
897
898 for (i = 0; i < base->n_games; ++i) {
899 if (game_score(base->game + i) == 0) continue;
900 game_export_text(base->game + i, stdout);
901 n_error = game_analyze(base->game + i, search, n_empties, apply_correction);
902 if (n_error) {
903 printf("Game #%d contains %d errors", i, n_error);
904 if (apply_correction) {
905 if (game_analyze(base->game + i, search, n_empties, false)) printf("... correction failed! ***BUG DETECTED!***\n");
906 else printf("... corrected!\n");
907 } else putchar('\n');
908 }
909 printf("%d/%d %.1f %% done.\r", i + 1, base->n_games, 100.0 * (i + 1) / base->n_games); fflush(stdout);
910 }
911}
912
919void base_complete(Base *base, Search *search)
920{
921 int i, n;
922 int completed;
923
924 for (i = n = 0; i < base->n_games; ++i) {
925 completed = 0;
926 if (game_complete(base->game + i, search) > 0) completed = 1;
927 n += completed;
928 if (completed || (i % 1000) == 0) {
929 printf("%d/%d games completed (%.1f %% done).\r", n, i + 1, 100.0 * (i + 1) / base->n_games); fflush(stdout);
930 }
931 }
932 printf("%d/%d games completed (all done). \n", n, i + 1);
933}
934
943void base_compare(const char *file_1, const char *file_2)
944{
945 Base base_1[1], base_2[2];
946 PositionHash hash[1];
947 Board board[1];
948 int i, j;
949 long long n_1, n_2, n_2_only;
950
951 base_init(base_1);
952 base_init(base_2);
953 n_1 = 0;
954 n_2 = 0;
955 n_2_only = 0;
956
957 base_load(base_1, file_1);
959 for (i = 0; i < base_1->n_games; ++i) {
960 Game *game = base_1->game + i;
961 *board = *game->initial_board;
962 for (j = 0; j < 60 && game->move[j] != NOMOVE; ++j) {
963 if (!game_update_board(board, game->move[j])) break; // BAD MOVE -> end of game
964 if (positionhash_append(hash, board)) {
965 ++n_1;
966 }
967 }
968 }
969 base_free(base_1);
970
971 base_load(base_2, file_2);
972 for (i = 0; i < base_2->n_games; ++i) {
973 Game *game = base_2->game + i;
974 *board = *game->initial_board;
975 for (j = 0; j < 60 && game->move[j] != NOMOVE; ++j) {
976 if (!game_update_board(board, game->move[j])) break; // BAD MOVE -> end of game
977 if (positionhash_append(hash, board)) {
978 ++n_2_only;
979 }
980 }
981 }
982
985 for (i = 0; i < base_2->n_games; ++i) {
986 Game *game = base_2->game + i;
987 *board = *game->initial_board;
988 for (j = 0; j < 60 && game->move[j] != NOMOVE; ++j) {
989 if (!game_update_board(board, game->move[j])) break; // BAD MOVE -> end of game
990 if (positionhash_append(hash, board)) {
991 ++n_2;
992 }
993 }
994 }
995 base_free(base_2);
996
998
999 printf("%s : %lld positions - %lld original positions\n", file_1, n_1, n_1 - (n_2- n_2_only));
1000 printf("%s : %lld positions - %lld original positions\n", file_2, n_2, n_2_only);
1001 printf("%lld common positions\n", n_2-n_2_only);
1002}
1003
static bool wthor_header_write(WthorHeader *wheader, FILE *f)
Read wthor header.
Definition base.c:84
void base_to_problem(Base *base, const int n_empties, const char *problem)
Convert a game database to a set of problems.
Definition base.c:841
void base_analyze(Base *base, Search *search, const int n_empties, const bool apply_correction)
Base analysis.
Definition base.c:893
static void wthor_players_save(WthorBase *base, const char *file)
Load wthor players.
Definition base.c:174
bool base_load(Base *base, const char *file)
Load a game database.
Definition base.c:740
void base_save(const Base *base, const char *file)
Save a game database.
Definition base.c:788
void base_complete(Base *base, Search *search)
Base analysis.
Definition base.c:919
void wthor_edaxify(const char *file)
Change players to "Edax (delorme)" and tourney to "Etudes" in a wthor base.
Definition base.c:651
void base_to_FEN(Base *base, const int n_empties, const char *problem)
Convert a game database to a set of problems.
Definition base.c:867
static void wthor_players_init(WthorBase *base)
Init wthor players.
Definition base.c:113
static void wthor_header_set(WthorHeader *wheader, unsigned int n_games, unsigned int n, unsigned int year)
Set wthor header.
Definition base.c:28
void wthor_init(WthorBase *base)
Initialize a Wthor base.
Definition base.c:316
static void wthor_players_load(WthorBase *base, const char *file)
Load wthor players.
Definition base.c:131
void base_unique(Base *base)
Make games unique in the game database.
Definition base.c:720
void wthor_eval(const char *file, Search *search, unsigned long long histogram[129][65])
Test Eval with a wthor base.
Definition base.c:611
void base_init(Base *base)
Initialize a game database.
Definition base.c:672
void wthor_print_game(WthorBase *base, int i, FILE *f)
print a wthor game.
Definition base.c:446
bool wthor_save(WthorBase *base, const char *file)
Save a wthor base.
Definition base.c:387
bool base_to_wthor(const Base *base, WthorBase *wthor)
Convert to a wthor base.
Definition base.c:417
static void wthor_tournaments_load(WthorBase *base, const char *file)
Load wthor tournaments.
Definition base.c:243
int wthor_player_get(WthorBase *base, const char *name)
Get a Wthor player's index.
Definition base.c:210
bool wthor_load(WthorBase *base, const char *file)
Load a wthor base.
Definition base.c:332
void wthor_free(WthorBase *base)
Free a wthor base.
Definition base.c:373
static void wthorgame_get_board(WthorGame *game, const int n_empties, Board *board, int *player)
Get a position from a Wthor game.
Definition base.c:474
void wthor_test(const char *file, Search *search)
Test Search with a wthor base.
Definition base.c:516
void base_append(Base *base, const Game *game)
Add a game to a game database.
Definition base.c:696
void base_free(Base *base)
Free resources of a game database.
Definition base.c:684
int pv_check(const Board *init_board, Line *pv, Search *search)
Verify that a PV does not contain errors.
Definition base.c:502
static bool wthor_header_read(WthorHeader *wheader, FILE *f)
Read wthor header.
Definition base.c:54
void base_compare(const char *file_1, const char *file_2)
Base Compare.
Definition base.c:943
#define foreach_wthorgame(wgame, wbase)
Definition base.h:62
bool board_check_move(const Board *board, Move *move)
Check if a move is legal.
Definition board.c:452
void board_print_FEN(const Board *board, const int player, FILE *f)
print using FEN description.
Definition board.c:1297
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
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
bool board_is_pass(const Board *board)
Check if current player should pass.
Definition board.c:1191
void board_pass(Board *board)
Passing move.
Definition board.c:503
@ NOMOVE
Definition const.h:37
@ WHITE
Definition const.h:43
@ BLACK
Definition const.h:42
void game_export_ggf(const Game *game, FILE *f)
Write a game to the Generic Game Format (ggf) file.
Definition game.c:713
void game_import_text(Game *game, FILE *f)
Read a game from a text file.
Definition game.c:451
void game_read(Game *game, FILE *f)
Read a game from a binary file.
Definition game.c:429
int game_analyze(Game *game, Search *search, const int n_empties, const bool apply_correction)
Analyze an endgame.
Definition game.c:1532
int game_complete(Game *game, Search *search)
Terminate an unfinished game.
Definition game.c:1625
bool game_update_board(Board *board, int x)
update a board.
Definition game.c:153
void game_export_sgf(const Game *game, FILE *f)
Definition game.c:944
void wthor_to_game(const WthorGame *thor, Game *game)
convert a Wthor game to a Game.
Definition game.c:340
void game_import_ggf(Game *game, FILE *f)
Read a game from the Generic Game Format (ggf) file.
Definition game.c:582
bool game_equals(const Game *game_1, const Game *game_2)
Test if two games are equal.
Definition game.c:114
void game_import_wthor(Game *game, FILE *f)
Read a game from a Wthor file.
Definition game.c:487
void game_export_text(const Game *game, FILE *f)
Write a game to a text file.
Definition game.c:467
void game_import_pgn(Game *game, FILE *f)
Read a game from a pgn file.
Definition game.c:955
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 game_to_wthor(const Game *game, WthorGame *thor)
convert a Game to a Whor game.
Definition game.c:366
void game_import_sgf(Game *game, FILE *f)
Read a game from a sgf file.
Definition game.c:823
void game_write(const Game *game, FILE *f)
Write a game to a binary file.
Definition game.c:440
void game_export_pgn(const Game *game, FILE *f)
Write a game to a pgn file.
Definition game.c:1203
bool game_get_board(const Game *game, const int ply, Board *board)
Get the board after 'ply' move.
Definition game.c:195
int game_score(const Game *game)
Compute the final score of the game, for the initial player.
Definition game.c:233
int move_from_wthor(int x)
Coordinates conversion from wthor to edax.
Definition game.c:38
void line_print(const Line *line, int width, const char *separator, FILE *f)
Print a move sequence.
Definition move.c:610
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
void line_copy(Line *dest, const Line *src, const int from)
Copy part of a sequence to another sequence.
Definition move.c:591
Options options
Definition options.c:22
void positionhash_delete(PositionHash *hash)
Free the hash table.
Definition perft.c:724
bool positionhash_append(PositionHash *hash, const Board *b)
Append a position to the hash table.
Definition perft.c:738
void positionhash_init(PositionHash *hash, int bitsize)
Initialisation of the hash table.
Definition perft.c:709
Move generator test header file.
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
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
Definition base.h:48
Game * game
Definition base.h:49
int n_games
Definition base.h:50
int size
Definition base.h:51
Definition board.h:26
Definition game.h:22
char move[60]
Definition game.h:33
char name[2][32]
Definition game.h:32
Board initial_board[1]
Definition game.h:23
Definition move.h:35
Definition move.h:20
int x
Definition move.h:22
int level
Definition options.h:40
bool pv_check
Definition options.h:72
int hash_table_size
Definition options.h:25
Definition perft.h:27
unsigned long long n_nodes
Definition search.h:49
int score
Definition search.h:45
long long time
Definition search.h:48
Line pv[1]
Definition search.h:47
Definition search.h:95
const char * separator
Definition search.h:145
Result * result
Definition search.h:151
const char * header
Definition search.h:144
struct Search::@25 options
int verbosity
Definition search.h:142
Definition base.h:38
int n_players
Definition base.h:43
WthorHeader header[1]
Definition base.h:39
WthorGame * game
Definition base.h:44
char(* tournament)[26]
Definition base.h:40
int n_tournaments
Definition base.h:41
int n_games
Definition base.h:45
char(* player)[20]
Definition base.h:42
Definition game.h:38
signed char theoric_score
Definition game.h:40
char x[60]
Definition game.h:41
short tournament
Definition game.h:39
signed char score
Definition game.h:40
short white
Definition game.h:39
short black
Definition game.h:39
Header for wthor files.
Definition base.h:24
char month
Definition base.h:27
char depth
Definition base.h:31
char year
Definition base.h:26
unsigned short n
Definition base.h:33
char day
Definition base.h:28
unsigned short game_year
Definition base.h:34
char century
Definition base.h:25
char reserved
Definition base.h:32
int n_games
Definition base.h:35
char game_type
Definition base.h:30
char board_size
Definition base.h:29
void time_print(long long t, bool justified, FILE *f)
Print time as "D:HH:MM:SS.CC".
Definition util.c:131
void string_to_lowercase(char *s)
Change all char of a string to lowercase.
Definition util.c:355
void path_get_dir(const char *path, char *dir)
Extract the directory of a file path.
Definition util.c:888
#define error(...)
Display an error message as "ERROR : filename : funcname : line number : ...".
Definition util.h:361
#define info(...)
Display a message.
Definition util.h:382
#define warn(...)
Display a warning message as "WARNING : ... ".
Definition util.h:373